網站首頁 編程語言 正文
Timestamp只保留日期不顯示時間
Timestamp.date()
拿到DataFrame中的一個時間戳后,加一個**.date()**即可
for time in df['日期']):
? ? print(time.date())
pandas從日期屬性中提取年月日
在數據挖掘過程中,日期屬性是非數值屬性, 不能直接輸入到模型,將日期屬性拆分成年、月和日是必要的。
date屬性是object類型的, 通過取單元格可以發現它是字符串類型,這樣很容易提取年、月、日
將日期屬性拆分成年、月、日
代碼如下:
def DateSplit(df, col):
"""
split the object of '2010-01-02' into year(2010), month(1) and day(2).
:param df: to operate data (type:DataFrame)
:param col: column label of date object (type:str)
:return: converted date (type: DataFrame)
"""
year, month, day = [], [], []
data = df.loc[:, col].values
df = df.drop([col], axis=1)
for i in range(data.shape[0]):
year.append(int(data[i][:4]))
month.append(int(data[i][5:7]))
day.append(int(data[i][8:]))
date = pd.DataFrame({'year': year, 'month': month, 'day': day})
result = pd.concat([date, df], axis=1)
return result
pm25_train = pd.read_csv("./datasets_PM25/pm25_train.csv")
data= DateSplit(df=pm25_train,col='date')
data.head(10)
原文鏈接:https://blog.csdn.net/piggy0306/article/details/116015054
相關推薦
- 2022-07-22 CSS設置元素隱藏的4種方法
- 2022-07-28 聊聊docker跨主機之間容器通信問題_docker
- 2022-09-26 車載藍牙PIN碼是什么
- 2022-09-17 Python?pandas?重命名索引和列名稱的實現_python
- 2023-11-15 latex報錯:Misplaced alignment tab character &. .
- 2023-07-02 oracle實現根據字段分組排序,取其第一條數據_oracle
- 2023-01-05 find?命令全集_linux shell
- 2022-05-02 Redis使用命令行與多數據庫配置_Redis
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支