| 價錢 | 數量 | 高峰時間 |
|---|---|---|
| 10.4 | 3 | 2021-11-08 14:26:00-05:00 |
dataframe = ddg
hightime 的資料型別是 datetime64[ns, America/New_York]
我希望高峰時間只有 14:26:00(擺脫 2021-11-08 和 -05:00),但是在使用下面的代碼時出現錯誤
ddg['high_time'] = ddg['high_time'].dt.strftime('%H:%M')
uj5u.com熱心網友回復:
我認為因為它不是正確的列名:
# Your code
>>> ddg['high_time'].dt.strftime('%H:%M')
...
KeyError: 'high_time'
# With right column name
>>> ddg['high time'].dt.strftime('%H:%M')
0 14:26
Name: high time, dtype: object
# My dataframe:
>>> df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1 entries, 0 to 0
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 price 1 non-null float64
1 quantity 1 non-null int64
2 high time 1 non-null datetime64[ns, America/New_York]
dtypes: datetime64[ns, America/New_York](1), float64(1), int64(1)
memory usage: 152.0 bytes
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/362336.html
