0

When I do pd.read_csv('FileName.csv'), I get the time column separate along with the rest of the data as shown:

enter image description here

When I do pd.read_csv('FileName.csv', , index_col=[0], parse_dates = [0]), knowing time in my data is index 0,I get this:

enter image description here

I checked the type of each and they are the same, however, when I try to do some analysis it work on one and it doesn't work on the other, like the resample function, it only work with the second dataframe.

Also, I can't use the time column in the second command. I have been looking but maybe am not familiar with key words, I would really appreciate the help! Thanks!

Moody
  • 35
  • 1
  • 8

1 Answers1

1

Your issue is related to index. In the first case, there is a separate index column (you can see in it the values 0, 1, ...). In the second case, the index is actually your Time column. So as resampling works only when you have a datetime-like index, the second approach works. But you cannot access the values of the index using Time column name (use .index if you need).

Yury
  • 20,618
  • 7
  • 58
  • 86
  • Thank u! So is there is a way to convert between the two cases? I am trying to resample my data and then use it with FbProphet for forecasting. Prophet only works if time is not indexed. So what I did is I made my time as the index then resampled, then saved the dataframe as a csv file, then read it without the parse to over come this problem. But I feel that this is tedious and maybe there is more direct way – Moody Jun 28 '22 at 15:56
  • 1
    Yes, after resampling, you can call `reset_index`, and then rename the column from `index` to `Time`. – Yury Jun 28 '22 at 16:02
  • Thank u! Appreciate ur help. How can I do resampling while my timestamp data have a timezone GMT-7? I stripped down my time stamp from the time zone, but when the daylight-change happens on March, the resample gives me NaN during this hour change. I got an advice to convert it to UTC – Moody Jun 28 '22 at 21:01
  • Actually, I have never faced with this issue, so I have no clue. However, it seems that you can use `.tz_convert("UTC")` method call to convert a datetime column. – Yury Jun 29 '22 at 08:04