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)?
>Solution :
import pandas as pd
date_array = [ [2022,1,16], [2022,1,18], [2022,2,12], [2022,3,24]]
date_df = pd.DataFrame(date_array, columns=['year', 'month', 'day'])
date_df['date'] = pd.to_datetime(date_df[['year', 'month', 'day']], format='%d/%m/%Y')
And if you’d like you can drop extra columns