Datumsangaben richtig aus der Excel verarbeiten zwecks Plotten
Verfasst: Samstag 28. November 2020, 00:26
Hallo zusammen, Ich habe ein Problem, und zwar möchte ich einen Graph plotten, indem ich Daten aus einer spezifischen Zeilenrange in Ecxel einlese. Die Daten müssen immer über das Datum aufgetragen werden. Soweit klappt das ja auch. Ich habe die Daten mit .iloc in der Excel ausgewählt nur das gleiche beim Datum klappt nicht so recht.
So erhalte ich die Fehlermeldung "x and y must have same first dimension, but have shapes (72564,) and (13282,)" Ist ja auch logisch, aber mir fällt leider dazu keine Lösung ein.
Code: Alles auswählen
import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_excel(r'C:\Users\marco\Desktop\Gm.xlsx', skiprows=0, sheet_name='MASCHDAT') df = pd.DataFrame(data, columns= ['DATUM','W020','W023'])
df['DATUM'] = df['DATUM'].apply(pd.to_datetime)
df.set_index('DATUM',inplace=True)
plt.rcParams['figure.figsize'] = (15, 8)
x = df.index
y1 = df['W020'].iloc[47220:60502]
y2 = df['W023'].iloc[47220:60502]
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
curve1 = ax1.plot(x, y1, label='W020', color='r')
curve2 = ax2.plot(x, y2, label='W023', color='b')
plt.plot()
plt.show()
df.head()
df.tail()
print(df.head())
print(df.tail())