我从datetime
到2014-12-1
创建了2014-12-31
个对象的数组,但是我需要从其中删除2014-12-29
条目。我该怎么办?
答案 0 :(得分:2)
使用boolean indexing
或Index.drop
:
data = pd.date_range('2014-12-1', '2014-12-31')
print (data)
DatetimeIndex(['2014-12-01', '2014-12-02', '2014-12-03', '2014-12-04',
'2014-12-05', '2014-12-06', '2014-12-07', '2014-12-08',
'2014-12-09', '2014-12-10', '2014-12-11', '2014-12-12',
'2014-12-13', '2014-12-14', '2014-12-15', '2014-12-16',
'2014-12-17', '2014-12-18', '2014-12-19', '2014-12-20',
'2014-12-21', '2014-12-22', '2014-12-23', '2014-12-24',
'2014-12-25', '2014-12-26', '2014-12-27', '2014-12-28',
'2014-12-29', '2014-12-30', '2014-12-31'],
dtype='datetime64[ns]', freq='D')
print (data[data != '2014-12-29'])
DatetimeIndex(['2014-12-01', '2014-12-02', '2014-12-03', '2014-12-04',
'2014-12-05', '2014-12-06', '2014-12-07', '2014-12-08',
'2014-12-09', '2014-12-10', '2014-12-11', '2014-12-12',
'2014-12-13', '2014-12-14', '2014-12-15', '2014-12-16',
'2014-12-17', '2014-12-18', '2014-12-19', '2014-12-20',
'2014-12-21', '2014-12-22', '2014-12-23', '2014-12-24',
'2014-12-25', '2014-12-26', '2014-12-27', '2014-12-28',
'2014-12-30', '2014-12-31'],
dtype='datetime64[ns]', freq=None)
或者:
print (data.drop(pd.Timestamp('2014-12-29')))
答案 1 :(得分:0)
在当天使用布尔值检查
df = df[df['date'] !='2014-12-29']