假設(shè)我有一個(gè)如下所示的 DataFrame: timestamp id value0 2020-09-27 10:00:00 a 100 2020-09-27 10:00:00 b 130 2020-09-27 10:00:00 c 160 2020-09-27 10:01:00 a 110 2020-09-27 10:01:00 b 140 2020-09-27 10:01:00 c 170 2020-09-27 10:02:00 a 120 2020-09-27 10:02:00 b 15我想創(chuàng)建一個(gè)新的 DataFrame,其中包含特定時(shí)間戳處每個(gè) id 的值的列。 a b c2020-09-27 10:00:00 10 13 162020-09-27 10:01:00 11 14 172020-09-27 10:02:00 12 15 NaN我嘗試過以下方法:df2 = pd.DataFrame(df['timestamp'].unique())for unique in df['id'].unique(): df2 = df2.join(df[df['id']==unique]['value']) df2.rename(columns={"value": unique})但是,我收到以下錯(cuò)誤:ValueError: columns overlap but no suffix specified: Index(['value'], dtype='object')有人可以解釋一下出了什么問題和/或獲得結(jié)果的更好方法是什么嗎?
使用時(shí)間序列中每個(gè) id 的值的列創(chuàng)建一個(gè)新的 pandas 數(shù)據(jù)框
慕尼黑8549860
2023-09-12 16:58:39