我无法对数据帧进行分组。我想分组并将索引设置为ID

2024-10-05 11:52:17 发布

您现在位置:Python中文网/ 问答频道 /正文

THIS IS WHAT I TRIED

weather = pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv')
weather.Date = pd.to_datetime(weather.Date)
weather = weather.sort_values(by = ['Date','ID']).reset_index(drop = True)

weather.set_index(weather['ID'], inplace =True)


weather.groupby('ID', as_index = True, axis = 0)

no = weather.Date.nunique()
print(weather)

我想在一个特定的ID和元素上绘制一个数据值与日期的关系图


Tags: csvtoidtruereaddatadatetimedate
1条回答
网友
1楼 · 发布于 2024-10-05 11:52:17

我试着重新键入一些数据来尝试和处理它,但是很难正确地完成这一切。你真的必须像特伦顿·麦金尼所说的那样提供你所有的数据

你可能会得到错误:ValueError: 'ID' is both an index level and a column label, which is ambiguous.我想解决这个问题的办法是在https://github.com/pandas-dev/pandas/issues/21080,但我不确定

相关问题 更多 >

    热门问题