3
A
回答
1
如果時間戳:
df['timestamp'] = df['timestamp'].dt.floor('d')
如果字符串:
df['timestamp'] = df['timestamp'].str.split().str[0]
樣品:
df = pd.DataFrame({'timestamp':pd.date_range('2016-06-29 15:46:43.895000',
periods=3,
freq='2000T')})
print (df)
timestamp
0 2016-06-29 15:46:43.895
1 2016-07-01 01:06:43.895
2 2016-07-02 10:26:43.895
print (type(df.loc[0, 'timestamp']))
<class 'pandas._libs.tslib.Timestamp'>
df['timestamp'] = df['timestamp'].dt.floor('d')
print (df)
timestamp
0 2016-06-29
1 2016-07-01
2 2016-07-02
df = pd.DataFrame({'timestamp':['2016-06-20 15:46:43.895000',
'2016-06-22 15:46:43.895000',
'2016-06-29 15:46:43.895000']})
print (df)
timestamp
0 2016-06-20 15:46:43.895000
1 2016-06-22 15:46:43.895000
2 2016-06-29 15:46:43.895000
print (type(df.loc[0, 'timestamp']))
<class 'str'>
df['timestamp'] = df['timestamp'].str.split().str[0]
print (df)
timestamp
0 2016-06-20
1 2016-06-22
2 2016-06-29
1
我們可以使用.dt.normalize()
方法:
df['timestamp'] = df['timestamp'].dt.normalize()
0
df['timestamp']=pd.to_datetime(df['timestamp']).dt.strftime('%Y-%m-%d')
相關問題
- 1. Python 3中,熊貓 - 刪除列,而不刪除頁眉
- 2. 熊貓 - 刪除列
- 3. 在大熊貓數據幀列刪除
- 4. 熊貓:Set_index功能不會刪除列
- 5. 用大熊貓刪除索引列表
- 6. 大熊貓據幀爆炸列內容
- 7. Ruby中的散列數組 - 刪除不需要的內容
- 8. 熊貓DataFrame:從列中的字符串中刪除不需要的部分
- 9. 大熊貓GROUPBY值在不同的列
- 10. 熊貓數據幀輸出需要是字符串而不是列表
- 11. 熊貓 - 刪除多個空列
- 12. 熊貓根據列名刪除列表
- 13. 大熊貓尋找scikits.statsmodels而不是statsmodels
- 14. 隱藏軸標籤而已,而不是整個軸,在大熊貓情節
- 15. 組合大熊貓行,其中不同列需要不同的動作
- 16. 熊貓當列是一個整數
- 17. 輸出不必要的陣列,熊貓
- 18. 而不刪除內容
- 19. 刪除不需要的列透視
- 20. 大熊貓:to_numeric多個列
- 21. 大熊貓:一個列表
- 22. 添加一個熊貓列而不創建一個列表
- 23. 大熊貓 - 內存不足
- 24. 刪除所有列,除了少數中的python-大熊貓
- 25. 刪除與從大熊貓
- 26. 熊貓比較兩個數據幀並刪除一列中匹配的內容
- 27. 熊貓 - 刪除DataFrame的最後一列
- 28. 刪除熊貓中的索引列
- 29. 刪除熊貓列中的字符
- 30. 刪除列表的內容不反覆
能告訴你,你已經試過的任何代碼? –
如果我的(或其他)答案有幫助,請不要忘記[接受](http://meta.stackexchange.com/a/5235/295067) - 點擊答案旁邊的複選標記('✓')將其從灰色切換到填充。謝謝。 – jezrael