pandas 时间格式化
时间: 2023-08-20 22:04:57 浏览: 96
pandas 时间格式转换的实现
要对Pandas中的时间列进行格式化,可以使用`pd.to_datetime()`函数来完成。该函数可以将时间列转换为Pandas的时间数据类型。可以使用以下代码将时间列转换为年-月-日的格式:
```python
df['Date'] = pd.to_datetime(df['Date']).dt.strftime('%Y-%m-%d')
```
这将会将"Date"列中的所有时间转换为年-月-日的格式,存储在同一列中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [pandas日期格式](https://blog.csdn.net/Java_KW/article/details/124108784)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Pandas中的字符串和时间转换与格式化](https://blog.csdn.net/qq_37944726/article/details/128585466)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文