Reputation: 31
I have a CSV file which contains a date in the format 2011,1,10,
The format in my dataframe, which I am loading that date into, should be 2011-01-10
.
I am using the following code to load the date out of the file:
read_csv("test.csv", parse_date=[[0,2]])
How do I convert it to read in as 2011-01-10?
Upvotes: 2
Views: 1116
Reputation: 375485
You nearly had it! The correct syntax for read_csv
is (parse_dates
):
In [1]: import pandas as pd
In [2]: pd.read_csv("test.csv", parse_dates=[[0,1,2]])
Out[2]:
year_month_day
0 2011-01-10 00:00:00
Where test.csv is:
year,month,day
2011,1,10
Upvotes: 3