I have a CSV which contains data as below:
date,datetime,year,month,date,value,name
20170430,2017-04-30 18:30:00,2017,04,30,NaN,A1
20170501,2017-05-01 18:30:00,2017,05,01,121.2,A1
20170430,2018-02-07 18:30:00,2018,02,07,1.23,B1
20170501,2017-07-10 18:30:00,2017,07,10,42.2,C1
20170430,2017-04-30 18:30:00,2017,04,30,32.1,C1
I need to have result as below, i.e. A1, B1, C1 values correspoding to date should be segregated as a seperate column:
date,datetime,year,month,date,A1,B1,C1
20170430,2017-04-30 18:30:00,2017,04,30,NaN,1.23,32.1
20170501,2017-05-01 18:30:00,2017,05,01,121.2,NaN,42.2
I tried to use python pandas pivot method with index as date and columns as name but am getting error as below which is expected because there are multiple entries for A1 and C1
ValueError: Index contains duplicate entries, cannot reshape
import pandas as pd
df = pd.read_csv("D:/datagenicAPI/finalCSV.csv")
print(df)
df1 = df.pivot(index="date", columns="name")
df1.to_csv("d:/datagenicAPI/test1.csv", sep=",")
I need to segregate as seperate columns, can I please know how to achieve the same with python pandas