0

我在 Pandas 数据框中有一个数据集,日期如下:

  • 2020 年 2 月 3 日
  • 19/3/2020

我想要这样的日期:

  • 2020 年 3 月 2 日
  • 2020 年 3 月 19 日

数据集称为 COVID,列称为“fecha_not”

这是我的数据集的一个样本:

在此处输入图像描述

4

2 回答 2

0

您好,您可以使用导入日期时间并将其应用于列,然后.strftime()您可以更改格式。在这里查看更多

import datetime

x = datetime.datetime(2020, 3, 19)
x.strftime("%m %d %Y")
'03 19 2020'
于 2020-12-03T21:34:46.760 回答
0

利用strftime

In [2]: df = pd.DataFrame({'fecha_not' : ['2/3/2020', '6/3/2020', '7/3/2020', '9/3/2020', '9/3/2020'],
   ...: 'Estodo' : "Leve"})
   ...: df
Out[2]: 
  fecha_not Estodo
0  2/3/2020   Leve
1  6/3/2020   Leve
2  7/3/2020   Leve
3  9/3/2020   Leve
4  9/3/2020   Leve

In [3]: df['fecha_not'] = pd.to_datetime(df.fecha_not).dt.strftime('%d/%m/%Y')
   ...: df
Out[3]: 
    fecha_not Estodo
0  03/02/2020   Leve
1  03/06/2020   Leve
2  03/07/2020   Leve
3  03/09/2020   Leve
4  03/09/2020   Leve
于 2020-12-03T21:41:32.333 回答