This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
i try to convert a stock price time series that is in EST to UTC in python and apply it for the dataframe. I think i am quite close to the solution with my code below:
df = pd.read_csv('stockdatafull.csv', delimiter=',')
df = df.drop(1)
df['time'] = pd.to_datetime(df['time'], format='%Y-%m-%d%H:%M:%S')
df.set_index('time', inplace=True)
eastern = pytz.timezone('US/Eastern')
df.index = df.index.tz_localize(pytz.utc).tz_convert(eastern)
# df.index = df.index.tz_localize('EST')
# df.index = df.index.tz_convert('Europe/Vienna')
# df['time'] = pd.to_datetime(df['time']) timedelta(hours=5)
df.to_csv('stockdata_UTC.csv')
The dataframe then looks like this: time is my index
time | open | high | low | close | volume 2021-11-19 15:00:00-05:00| 229.0000 |229.00 |228.5200 |229.000 |2269
with the -05:00 showing up in my index, i think i just have to apply the conversion to the dataframe. every time should be 5 hours to match with UTC. Could you please help me out?
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...