我在使用 python 中的 pandas 编辑日期时间格式方面需要帮助
I need help in editing the date-time format using pandas in python
我有一个时间是 UNIX 格式的数据。我使用以下代码将数据帧中的时间转换为 Unix 中的日期格式。
import pandas as pd
df = pd.read_csv(r'C:\Users\My Computer\Desktop\Data Analysis\BATS_SPY, 1D.csv')
df['time'] = pd.to_datetime(df['time'],unit='s')
print(df.head())
我得到的结果是
time
0 1993-01-29 14:30:00
1 1993-02-01 14:30:00
2 1993-02-02 14:30:00
3 1993-02-03 14:30:00
4 1993-02-04 14:30:00
如果我只想要日期(也就是我想从时间中排除14:30:00)怎么办
我的数据如下
time
0 728317800
1 728577000
2 728663400
3 728749800
4 728836200
带上你的约会系列:
df['date'] = df['time'].dt.floor('D')
我有一个时间是 UNIX 格式的数据。我使用以下代码将数据帧中的时间转换为 Unix 中的日期格式。
import pandas as pd
df = pd.read_csv(r'C:\Users\My Computer\Desktop\Data Analysis\BATS_SPY, 1D.csv')
df['time'] = pd.to_datetime(df['time'],unit='s')
print(df.head())
我得到的结果是
time
0 1993-01-29 14:30:00
1 1993-02-01 14:30:00
2 1993-02-02 14:30:00
3 1993-02-03 14:30:00
4 1993-02-04 14:30:00
如果我只想要日期(也就是我想从时间中排除14:30:00)怎么办
我的数据如下
time
0 728317800
1 728577000
2 728663400
3 728749800
4 728836200
带上你的约会系列:
df['date'] = df['time'].dt.floor('D')