#πŸ”’ reading csv in jupyter gets rid of datetimeindex

12 messages Β· Page 1 of 1 (latest)

vestal edge
#

i used thios short python script to concatonate and save a new csv with the idnex beeing a datetime dtype:

df['ts']= pd.to_datetime(df['ts'])
df=df.set_index(df['ts'])
df=df.drop(columns=['ts'])
df.index = df.index.tz_convert('Europe/Berlin')

df.to_csv('C:\\Privat\\Python_VSC\\Spotify\\MyData_2025\\Data_concat.csv')

in the json's the ts column was given in UTC. (i concatonated the Json's into a csv.

Now i tried opening the new File in a jupyter notebook only to get that response:

df.index.dtype
clever hatchBOT
#

@vestal edge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vestal edge
#

but trying to run ```
df.index= pd.to_datetime(df.index)

 returns the following
ValueError: Array must be all same time zone
#

and that makes sense, cause wehn looking at the value_counts of teh idnex we see different conversions,. which i dont understanmd what they mean...

vestal edge
#

2021-01-06T19:04:34Z Time Stamps in the originall .json ahve been looking like that

cedar gazelle
#

that difference (+01, +02) looks like daylight savings?

#

I'd just save as UTC instead

cedar gazelle
clever hatchBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.