'Pandas csv imported data as GMT time, converted to ET, but still graphs as GMT
With this input data:
Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload,Share,IP Address
21313,Data Room,"New York, NY",2022-01-26T14:45:03.077906Z,303.64182503660265,42.832,92611485.22339329,4696657.256436758,,66.30.193.6
33699,new york mega,"New York, NY",2022-01-26T14:50:00.632113Z,303.6412316749501,22.753,137666574.18319866,4958464.430089439,,66.30.193.6
28025,Wnet,"New York, NY",2022-01-26T14:55:00.607109Z,303.64182503660265,21.328,135736384.87162516,5445174.807892095,,66.30.193.6
28025,Wnet,"New York, NY",2022-01-26T15:05:00.392564Z,303.64182503660265,22.196,105562361.61923751,5223765.9967212705,,66.30.193.6
28025,Wnet,"New York, NY",2022-01-26T15:10:00.764044Z,303.64182503660265,22.001,97691113.37578829,4932346.0134777855,,66.30.193.6
33699,new york mega,"New York, NY",2022-01-26T15:15:00.670005Z,303.6412316749501,22.955,84284289.38315299,4746053.362229474,,66.30.193.6
6166,Webair.com,"Garden City, NY",2022-01-26T15:20:00.623832Z,280.0394387965954,21.941,78580308.10473917,4430882.066164639,,66.30.193.6
33699,new york mega,"New York, NY",2022-01-26T15:25:00.539652Z,303.6412316749501,20.797,77345481.37853824,4841340.618905533,,66.30.193.6
21313,Data Room,"New York, NY",2022-01-26T15:35:00.518041Z,303.64182503660265,22.255,112304768.91188963,5047458.518319914,,66.30.193.6
The data in the column Timestamp is GMT ("Z"). However I convert it to America/New_York correctly (as I can tell when I look at the datatable separately.) And yet the x axis in the graph is showing GMT. Why?
fig = plt.figure(figsize=(18,6))
ax = fig.add_subplot(1,1,1)
df = pd.read_csv("speedtest.csv", parse_dates=['Timestamp'])
df['Timestamp'] = df['Timestamp'].dt.tz_convert('America/New_York')
df['Download'] = df['Download']/1000000.0
subset = df[(df['Timestamp']>"2022-01-24") & (df['Distance']>0)]
ax.scatter('Timestamp', 'Download', data=subset)
ax.set_title("Speedtest")
ax.tick_params(which='minor', length=10)
ax.tick_params(which='major', length=20)
ax.xaxis.set_minor_locator(mdates.HourLocator(interval=1))
ax.xaxis.set_major_locator(mdates.HourLocator(interval=3))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H:%M'))
ax.grid(which='both', axis='both')
plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
