the_learning_child
the_learning_child

Reputation: 111

Removing a date from a date array

I created an array of datetime objects from 2014-12-1 to 2014-12-31, but i need to remove the 2014-12-29 entry from it. How do i do that ?

Upvotes: 0

Views: 509

Answers (2)

jezrael
jezrael

Reputation: 863791

Use boolean indexing or 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)

Or:

print (data.drop(pd.Timestamp('2014-12-29')))

Upvotes: 3

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32031

use boolean check for that day

df = df[df['date'] !='2014-12-29']

Upvotes: 0

Related Questions