I have a data set in a Pandas data frame with dates like this:
- 2/3/2020
- 19/3/2020
And I want to have the dates like this:
- 3/2/2020
- 3/19/2020
The data set is called COVID and the column is called 'fecha_not'
This is a sample of my data set:
I have a data set in a Pandas data frame with dates like this:
And I want to have the dates like this:
The data set is called COVID and the column is called 'fecha_not'
This is a sample of my data set:
Use 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
Hello you can use import datetime and apply it to the column, then with .strftime()
you can change the format.
Check more here
import datetime
x = datetime.datetime(2020, 3, 19)
x.strftime("%m %d %Y")
'03 19 2020'