日期时间格式问题

时间:2020-07-10 10:21:40

标签: date-formatting python-datetime

我有一个DF,如下:

top5graph.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 405 entries, 0 to 404
Data columns (total 12 columns):
CountryName                  405 non-null object
CountryCode                  405 non-null object
**Date                         405 non-null int64**
School closing               405 non-null int64
Stay at home requirements    405 non-null int64
ConfirmedCases               405 non-null float64
ConfirmedDeaths              405 non-null float64
StringencyIndex              405 non-null float64
Continent_Name               405 non-null object
SCIndex                      405 non-null object
WFHIndex                     405 non-null object
NewDate                      405 non-null object
dtypes: float64(3), int64(3), object(6)
memory usage: 38.0+ KB

Original Dataset looks like this:

20200301

运行命令以将“日期”列转换为日期格式:

top5graph['Date'] = pd.to_datetime(top5graph['Date'])

The Output is:

1970-01-01 00:00:00.020200301

这是我尝试过的:

  1. 将“日期”转换为字符串并删除“ 2020”-无效
  2. 使用parse_dates=[0]中的pd.read()重新加载数据集
  3. 试图提取“ 2020”之后的数字,但没有用
  4. 试图使用%Y%m%d格式转换格式也没有用

有人可以帮我弄清楚为什么会这样吗?

0 个答案:

没有答案