My DataFrame has multiple columns and one of them is not being read when I try to use indexing (eg bar_0617 = media_0617 ['Bar']). The following error appears: KeyError: 'Bar'. I do not know what to do, I already checked the file with my data and the column has this name, when calculating the average also appears the name right, but when I go to index to go through your data gives error. Thanks in advance "Here is the code
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
file = r'C:\Users\Jonat\OneDrive\Documentos\Faculdade\LAMCE\dadostratados1718.csv'
table = pd.read_csv(file, sep = ';')
#2017
table_2017 = table.query('ANO==2017')
#Cada mês
table_0617 = table_2017.query('MES==6')
table_0717 = table_2017.query('MES==7')
table_0817 = table_2017.query('MES==8')
table_0917 = table_2017.query('MES==9')
table_1017 = table_2017.query('MES==10')
table_1117 = table_2017.query('MES==11')
table_1217 = table_2017.query('MES==12')
media_0617 = np.mean(table_0617)
media_0717 = np.mean(table_0717)
media_0817 = np.mean(table_0817)
media_0917 = np.mean(table_0917)
media_1017 = np.mean(table_1017)
media_1117 = np.mean(table_1117)
media_1217 = np.mean(table_1217)
time = ['0617', '0717', '0817', '0917', '1017', '1117', '1217']
time = pd.DataFrame({'Tempo': time})
bar_0617 = media_0617['Bar']
bar_0717 = media_0717['Bar']
bar_0817 = media_0817['Bar']
bar_0917 = media_0917['Bar']
bar_1017 = media_1017['Bar']
bar_1117 = media_1117['Bar']
bar_1217 = media_1217['Bar']
bar = [bar_0617, bar_0717, bar_0817, bar_0917, bar_1017, bar_1117, bar_1217, bar_0118, bar_0218, bar_0318, bar_0418, bar_0518, bar_0618, bar_0718, bar_0818, bar_0918, bar_1018, bar_1118, bar_1218]
bar = pd.DataFrame({'Bar': bar})
serie_bar = pd.concat([bar, time], axis=1, join='inner') #Pressão
plt.plot(serie_bar['Tempo'], serie_bar['Bar']) #Pressão
plt.title('Pressão x Tempo', fontsize = '20')
plt.ylabel('Pressão (hPa)')
plt.xlabel('tempo')
plt.rcParams['figure.figsize'] = (11,7)
plt.savefig(r"C:\Users\Jonat\OneDrive\Documentos\Faculdade\LAMCE\variáveis\serie_bar.png", dpi=None, facecolor='w', edgecolor='w',orientation='landscape')
plt.show()