Multiple columns with the same name in Pandas

后端 未结 2 367
终归单人心
终归单人心 2021-01-04 13:24

I am creating a dataframe from a CSV file. I have gone through the docs, multiple SO posts, links as I have just started Pandas but didn\'t get it. The CSV file

2条回答
  •  时光取名叫无心
    2021-01-04 14:13

    I had a similar issue, not due to reading from csv, but I had multiple df columns with the same name (in my case 'id'). I solved it by taking df.columns and resetting the column names using a list.

    In : df.columns
    Out: 
    Index(['success', 'created', 'id', 'errors', 'id'], dtype='object')
    
    In : df.columns = ['success', 'created', 'id1', 'errors', 'id2']
    
    In : df.columns
    Out: 
    Index(['success', 'created', 'id1', 'errors', 'id2'], dtype='object')
    

    From here, I was able to call 'id1' or 'id2' to get just the column I wanted.

提交回复
热议问题