Search code examples
pandasplottimeseries

Can't visualise time series correctly in Python


I have a problem visualising time series in the format D/M/Y h/m/s

The following code works for the first day and produces incorrect output after that.

import pandas as pd
import matplotlib.pyplot as plt

cars = pd.read_csv('time_series.csv', parse_dates=['Ldatetime'], index_col='Ldatetime')
cars.plot()

enter image description here

Here is the data format:

enter image description here

If I remove the data parser, the plot looks fine but it's not recognised as time.

enter image description here


Solution

  • The data you provided contains days in December as well as June:

    date,car
    2023-12-06 23:20:00,12
    2023-12-06 23:25:00,19
    2023-12-06 23:30:00,10
    2023-12-06 23:35:00,13
    2023-12-06 23:40:00,13
    2023-12-06 23:45:00,15
    2023-12-06 23:50:00,14
    2023-12-06 23:55:00,9
    2023-06-13 00:00:00,5
    2023-06-13 00:05:00,4
    2023-06-13 00:10:00,7
    2023-06-13 00:15:00,6
    2023-06-13 00:20:00,7
    2023-06-13 00:25:00,7
    2023-06-13 00:30:00,4
    

    some of them are 06-13 and some of them are 12-06 The visualizations are correct.