'Pandas 'Timestamp' object is not subscriptable error
I have a data frame and I am trying to figure our days of the week for a data set.
df['day_of_week'] = df['CMPLNT_TO_DT'].dt.day_name()
TypeError: 'Timestamp' object is not subscriptable
Solution 1:[1]
Your problem is with an incorrect assignment.
df['date']=pd.date_range('2021/5/9', '2021/5/14')
df['date'].dt.day_name()
Output:
and:
df = pd.Timestamp('2017-01-01T12')
df['CMPLNT_TO_DT'].dt.day_name()
Output:
The problem is not with the .dt.day_name():
df = pd.Timestamp('2017-01-01T12')
df['CMPLNT_TO_DT']
again:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |



