pandas常用数据分析语法(四):时间处理
#数据类型转换
df.loc[:,'Arrest Date'] = pd.to_datetime(df['Arrest Date'])
#时间筛选
df= df.loc[(df.loc[:,'Arrest Date']<=pd.Timestamp('2019-1-1')),:]
df_2018 = df.loc[df.loc[:,'Arrest Date'].apply(lambda x: x.year == 2018),:]
id_a=data.loc[:,'Arrest Date'].apply(lambda x: x.year <=2019 and x.month==5)
id_b=data.loc[:,'Arrest Date'].between(pd.Timestamp('2019-4-30'),pd.Timestamp('2019-5-04'))
本文介绍了如何使用Pandas库进行时间序列数据分析,包括将数据列转换为日期时间格式,以及如何筛选特定时间段的数据。通过`pd.to_datetime`函数转换日期字符串,并利用时间筛选条件如年份和月份进行数据过滤,例如选取2018年的数据和2019年5月的数据。这些操作对于处理时间序列数据至关重要。
1420

被折叠的 条评论
为什么被折叠?



