0
我想在python中取消一列,但它並不完全符合我的期望。我的表(稱爲DF)類似於此:在Python中使用Unstack
station_id year Day1 Day2
210018 1916 4 7
1917 3 9
256700 1916 NaN 8
1917 6 9
我想在今年讓每stationn一年所有的日子都在一行中拆散。 1916年那兩天會再啓動第一,隨後2天,從1917年的210018臺和256700.
一個例子是這樣的:
station_id 1916 1917
210018 4 7 3 9
256700 NaN 8 6 9
我想使用此代碼:
df2=df.unstack(level='year')
df2.columns=df2.columns.swaplevel(0,1)
df2=df2.sort(axis=1)
我收到一個錯誤,說AttributeError: 'Series' object has no attribute 'columns'
。
任何幫助,將不勝感激。
謝謝!我雖然這是一個問題,但我一直讓station_id成爲索引而不是一年。 – spotter 2015-03-31 17:33:57