I have a DF, with timestamps that I converted to datetime(), and I want to create a Python table to aggreagate by month and year, but I get the following error:
ValueError: Duplicated level name: "TimeStamp", assigned to level 1, is already used for level 0
flowData =pd.read_csv('...')
flowData["TimeStamp"] = pd.to_datetime(flowData["TimeStamp"])
pv = flowData.pivot_table(index=flowData['TimeStamp'].dt.month,columns=flowData['TimeStamp'].dt.year, values='Value', aggfunc=np.mean)
pv.head()
Try renaming the indices:
pv = (flowData.pivot_table(index=flowData['TimeStamp'].dt.month.rename('month'),
columns=flowData['TimeStamp'].dt.year.rename('year'),
values='Value', aggfunc=np.mean))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.