import pandas as pd import matplotlib.pyplot as plt Read the Excel file and sheet df =…
- User
import pandas as pd import matplotlib.pyplot as plt
Read the Excel file and sheet
df = pd.read_excel('Plyny_export.xlsx', sheet_name='VARI_T401_ppm_rok')
Extract the month and year from the 'Tech.kontrola dňa' column
df['Month'] = df['Tech.kontrola dňa'].dt.strftime('%Y-%m')
Get the columns we're interested in
cols = ['Month', 'C2H2_ppm/rok', 'C2H4_ppm/rok', 'C2H6_ppm/rok', 'CO_ppm/rok', 'CH4_ppm/rok','C2H2_limit','C2H4_limit','C2H6_limit','CO_limit','CH4_limit' ] df = df[cols]
Loop over the columns and create a new plot for each gas
for col in cols[1:]: fig, ax = plt.subplots() df.plot(x='Month', y=col, ax=ax, kind='bar', color='blue') ax.set_xlabel('Rok - mesiac') ax.set_ylabel('Ročný prírastok ppm/rok') ax.set_title(f'Incrementation of {col} over time')
Add a red bold line for the C2H2_limit values
if col == 'C2H2_ppm/rok': ax.axhline(y=df['C2H2_limit'][0], color='red', linewidth=2)
Add a green bold line for the C2H4_limit values
if col == 'C2H4_ppm/rok': ax.axhline(y=df['C2H4_limit'][0], color='green', linewidth=2)
Add a purple bold line for the C2H6_limit values
if col == 'C2H6_ppm/rok': ax.axhline(y=df['C2H6_limit'][0], color='purple', linewidth=2)
Add an orange bold line for the CO_limit values
if col == 'CO_ppm/rok': ax.axhline(y=df['CO_limit'][0], color='orange', linewidth=2)
Add a black bold line for the CH4_limit values
if col == 'CH4_ppm/rok': ax.axhline(y=df['CH4_limit'][0], color='black', linewidth=2)
if col == 'C2H2_limit'or 'C2H4_limit' or 'C2H6_limit' or 'CO_limit' or 'CH4_limit':
break
Show the plots
plt.show()
- Assistant
The code reads an Excel file 'Plyny_export.xlsx' with a sheet named 'VARI_T401_ppm_rok'. It then extracts the year and month from the 'Tech.kontrola dňa' column and selects the columns of interest.
It then loops over the selected columns and creates a new plot for each gas using the
plot()method from Pandas, where each bar represents the annual increase in ppm for that gas.For C2H2, C2H4, C2H6, CO, and CH4 gases, the code adds a bold horizontal line for the limit value in each plot using the
axhline()method from Matplotlib.Finally, the code shows all the plots using the
show()method from Matplotlib.One potential issue with the code is that the break statement in the commented-out line would cause the loop to stop after the first gas limit is added. This could be problematic if multiple gases have the same limit value, as it would only be added to the first gas's plot.
- User
find out the frequency of exceeding the limit line in each graph and create one additional graph in which you plot it
- Assistant
To find out the frequency of exceeding the limit line in each graph, we can compare each value of the gas with its corresponding limit value and count the number of times the gas value exceeds its limit. We can then plot this information on a separate graph.