bar verhält sich unregelmäßig
Verfasst: Dienstag 17. August 2021, 13:31
Folgender Code funktioniert nicht:
Die Fehlermeldung ist, dass plt.bar nicht funktioniert: unsupported operand type(s) for -: 'str' and 'float'
Jedes Tutorial erzählt mir, dass mein Code funktionieren müsste! Was ist falsch?
Code: Alles auswählen
%matplotlib notebook
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(12345)
df = pd.DataFrame([np.random.normal(32000,200000,3650),
np.random.normal(43000,100000,3650),
np.random.normal(43500,140000,3650),
np.random.normal(48000,70000,3650)],
index=[1992,1993,1994,1995])
# print (df)
bottom_1_min = df.loc[int("1992")].min()
bottom_1_max = df.loc[int("1992")].max()
diff_1 = bottom_1_max - bottom_1_min
bottom_2_min = df.loc[int("1993")].min()
bottom_2_max = df.loc[int("1993")].max()
diff_2 = bottom_2_max - bottom_2_min
year = ["1992", "1993"]
diff = [diff_1, diff_2]
if isinstance(diff_1, np.generic):
print (diff_1)
plt.bar(year, diff)
plt.show()
Jedes Tutorial erzählt mir, dass mein Code funktionieren müsste! Was ist falsch?