Problem: When plotting a DataFrame with matplotlib, an error is encountered due to the index column being a datetime value.
Solution: To resolve this, a new column must be added that replicates the index column. This cloned column can then be used for plotting.
Implementation:
df3 = df3.reset_index()
df3['Time'] = df3.index
Alternatively, you can create the new column without resetting the index:
df3['new'] = df3.index
plt.plot(df3['magnetic_mag mean'], df3['Time'], label='FDI')
Additional Tips:
df = pd.read_csv('university2.csv', sep=";", skiprows=1, index_col='YYYY-MO-DD HH-MI-SS_SSS', parse_dates=True)
The above is the detailed content of How to Plot a DataFrame with a DateTime Index in Matplotlib?. For more information, please follow other related articles on the PHP Chinese website!