in Education by
I have some columns that have the same names. I would like to add a 1 to the repeating column names Data Date Type hi hello stat hi hello 1/1/2022 a 0 0 1 1 0 Desired Date Type hi hello stat hi1 hello1 1/1/2022 a 0 0 1 1 0 Doing mask = df['col2'].duplicated(keep=False) I believe I can utilize mask, but not sure how to efficiently achieve this without calling out the actual column. I would like to call the full dataset and allow the algorithm to update the dupe. Any suggestion is appreciated JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Use the built-in parser method _maybe_dedup_names(): df.columns = pd.io.parsers.base_parser.ParserBase({'usecols': None})._maybe_dedup_names(df.columns) # Date Type hi hello stat hi.1 hello.1 # 0 1/1/2022 a 0 0 1 1 0 This is what pandas uses to deduplicate column headers from read_csv(). Note that it scales to any number of duplicate names: cols = ['hi'] * 3 + ['hello'] * 5 pd.io.parsers.base_parser.ParserBase({'usecols': None})._maybe_dedup_names(cols) # ['hi', 'hi.1', 'hi.2', 'hello', 'hello.1', 'hello.2', 'hello.3', 'hello.4'] In pandas < 1.3: df.columns = pd.io.parsers.ParserBase({})._maybe_dedup_names(df.columns)

Related questions

0 votes
    In the code below I pivot a dataframe using an index date. After the pivot, I need to get the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Problem: Select first N rows and last row in Python Pandas. only gets 1 row which is index 9 and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    So I have a list of people, each of them are given more than 2 books, 4 books are possible. I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm having an issue currently with pulling from an API, getting a JSON dict, then flattening it, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm having an issue currently with pulling from an API, getting a JSON dict, then flattening it, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What is the function to set column names for a matrix? (a) names() (b) colnames() (c) col.names() ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. > newprice ... 164 In fact, this is what am doing: names(newprice)[1]...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Which of the following is used for testing for membership in the list of column names? (a) in (b) ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 29, 2021 in Education by JackTerrance
0 votes
    SQL structure such as table names, column names, and so on cannot be escaped, and thus user-supplied structure names are ... issue in a report-writing software. 1. True 2. False...
asked Mar 20, 2021 in Technology by JackTerrance
0 votes
    I have one Dataframe. Dataframe1: desc id result A 1 Yes A 2 No A 3 Yes A 4 No B 1 No ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I have one Dataframe. Dataframe1: desc id result A 1 Yes A 2 No A 3 Yes A 4 No B 1 No ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have one Dataframe. Dataframe1: desc id result A 1 Yes A 2 No A 3 Yes A 4 No B 1 No ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    i have multiple excel files with uniform column names, except for one. One file calls it EndOfMarchStatus, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
...