Home > Software engineering >  When I do pd.read_csv('FileName.csv', index_col=[0], parse_dates = [0]) it's differen
When I do pd.read_csv('FileName.csv', index_col=[0], parse_dates = [0]) it's differen

Time:06-29

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!

CodePudding user response:

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).

  • Related