2017-03-17 62 views
1

這是我的數據框(時間索引):卸下數據框柱(熊貓)某一天

     price 
time 
2015-11-07 00:00:00 180.250000 
2015-11-07 00:15:00 176.350000 
2015-11-07 00:30:00 177.533333 
2015-11-08 00:45:00 180.216667 

我想刪除一天的2015年11月7日「的所有條目,所以我嘗試:

remove = df.loc['2015-11-07] 
df.drop(remove) 

但我收到此錯誤labels ['price'] not contained in axis

回答

1

你需要通過DataFrameindex稱爲remove刪除:

remove = df.loc['2015-11-07'] 
print (remove) 
          price 
time       
2015-11-07 00:00:00 180.250000 
2015-11-07 00:15:00 176.350000 
2015-11-07 00:30:00 177.533333 

print (df.drop(remove.index)) 
          price 
time       
2015-11-08 00:45:00 180.216667 

另一種解決方案:

idx = df.index.difference(df.loc['2015-11-07'].index) 
print (idx) 
DatetimeIndex(['2015-11-08 00:45:00'], dtype='datetime64[ns]', name='time', freq=None) 

print (df.loc[idx]) 
          price 
time       
2015-11-08 00:45:00 180.216667