I have a Python array in the form:
K = [ [2022,1,16], [2022,1,18], [2022,2,12], [2022,3,24]]
This array contains dates within sub-arrays.
How can I turn it into a Pandas DataFrame with 1 column of dates in standard format (%d/%m/%Y)?
I have a Python array in the form:
K = [ [2022,1,16], [2022,1,18], [2022,2,12], [2022,3,24]]
This array contains dates within sub-arrays.
How can I turn it into a Pandas DataFrame with 1 column of dates in standard format (%d/%m/%Y)?
import datetime
K = [ [2022,1,16], [2022,1,18], [2022,2,12], [2022,3,24]]
dict_t ={"date": []}
import pandas as pd
for time_list in K:
dict_t["date"] += [datetime.datetime(*time_list)]
pd.DataFrame(dict_t)
#output
date
0 2022-01-16
1 2022-01-18
2 2022-02-12
3 2022-03-24
you can change the format this way
import datetime
K = [ [2022,1,16], [2022,1,18], [2022,2,12], [2022,3,24]]
dict_t ={"date": []}
import pandas as pd
for time_list in K:
dict_t["date"] += [datetime.datetime(*time_list)]
df = pd.DataFrame(dict_t)
df.style.format({"date": lambda t: t.strftime("%d/%m/%Y")})
date
0 16/01/2022
1 18/01/2022
2 12/02/2022
3 24/03/2022