user8224662
user8224662

Reputation: 133

CSV file_reading datetime

I have a csv file, and it has time column with format: yyyy-mm-dd hh:mm:ss

I want to plot other columns as a function of time. So i need to define "time". I have assigned to each time, a number, which is yyyymmddhhmmss.

However, it generates a jump between numbers, whenever date, or month or year chanegs.

How can I solve this?

Upvotes: 0

Views: 66

Answers (1)

Keith
Keith

Reputation: 4924

Fist you should format correctly. Pandas is aware of the object datetime but when you use some of the import functions it is taken as a string. So what you need to do is make sure the column is set as the datetime type not as a string.

df['date']  = pd.to_datetime(df['date'])

Now you can use the plot function or whatever in matplotlib. After plotting you should call

fig.autofmt_xdate()

to get the date ticks to work

Upvotes: 1

Related Questions