I have a CSV which has dates in this format:
Date
01/01/1997
02/01/1997
03/01/1997
04/01/1997
I am importing the data into a dataset using df = pd.read_csv('data.csv')
When I look at the data held in the dataframe it appears in a different format:
df['Date']
Date
1997-1-1
1997-1-2
1997-1-3
1997-1-4
I don't understand why this is happening.
I've tried Googling & looking on SOF but haven't been able to find the answer...
df["Date"].dtypeshow? I believepandashas automatically recognized that this column contains dates and converted them todatetypeobjects. You may wish to keepdf["Date"]in this format, however, and do what @DeepSpace suggested below. Or adddtype={"Date" : str}to yourread_csv()call to keep these values unchanged (and as strings).df['Date'].dtypegivesdtype('O')?? If I passdtype={'GMT': str}I still getdtype('O')dtype={"GMT" : str}do the dates look the way you want them to?dtype('O')- means 'object' (or string in pandas terminology)