0

Hope someone can help with plot problem that I know how to solve in Excel (axis type date/text), but how to do in Pandas. I want to plot timeseries with x-axis timestamp but graph print wrong like this pic Plot of timeseries with x-axis timestamp, graph is not fine

I read data like this:

paine = pd.read_csv('c:\data\paine3.csv', sep = ';', decimal = '.', skiprows=0,
    parse_dates=[['Date', 'Time']])

Date_Time   bar Temp    V
0   2021-06-01 17:00:00 7.16    25.97   4.0
1   2021-06-01 17:00:03 7.17    26.00   4.0
2   2021-06-01 17:00:06 7.18    26.00   4.0
3   2021-06-01 17:00:09 7.19    25.93   4.0
4   2021-06-01 17:00:12 7.19    26.00   4.0

If I plot before giving index, graph look ok but without timestamp.

paine['bar'].plot()

Graph ok , but without x-axis timestap

After I set datetime to index, then plot is like above picture.

paine.index = pd.to_datetime(paine['Date_Time'])
Artyom Akselrod
  • 946
  • 6
  • 14
  • on the first plot you linked, it looks like you have gaps in your time series. on the second plot it's just plotted against the index, so the gaps aren't visible anymore. how do you actually want to treat the gaps? just ignore? – FObersteiner Mar 18 '21 at 14:00
  • Second plot look like I want, but including x-axis timestamp. There is about 200000 points, 3sec interval and if timestamp should print every 12hr. – Sami Nyman Mar 18 '21 at 17:35
  • You could try to leave the date as string (not datetime) and us that as x-axis. Related: https://stackoverflow.com/q/38572534/10197418 – FObersteiner Mar 18 '21 at 19:08
  • Actually my original file is .txt where date and time indicated like this with quotation mark "06-01-2021" "17:00:00". When I read this file directly and do parse_dates=[['Date', 'Time']] , then time stamp on x-axis print fine. Problem was that I opened same file in Excel and saved in csv , then same row look like this 6.1.2021;17:00:00. Somehow parse_dates look work fine but x-axis timestamp will not print correctly. – Sami Nyman Mar 20 '21 at 09:04
  • Found solution to original problem. By default, the argument parse_dates will read date data with month first (MM/DD, MM DD, or MM-DD) format, and this arrangement is relatively unique in the United State. In most of the rest of the world, the day is written first (DD/MM, DD MM, or DD-MM). If you would like Pandas to consider day first instead of month, you can set the argument dayfirst to True. pd.read_csv('data/data_1.csv', parse_dates=['date'], dayfirst=True) – Sami Nyman Mar 21 '21 at 13:02

0 Answers0