簡體   English   中英

從dataframe列(Pandas)中刪除特定日期

[英]Remove a particular day from dataframe column (Pandas)

這是我的數據幀(時間是一個索引):

                     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-07'的所有條目,所以我嘗試了:

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

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

您需要通過名為removeDataFrame index 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM