text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('/kaggle/input/airquality2022/Konvertirani_vrednosti_novi1.csv')
df = df.drop(['Unnamed: 0'], axis=1)
df

df['day-night'] = df['hour'].apply(lambda x: 'day' if x in range(8, 20) else 'night')
df['grejna-negrejna'] = df.apply(lambda x: 'negrejna' if (x['month'] > 4 or (x['month'] == 4 and x['day'] >= 15)) and (x['month'] < 10 or (x['month'] == 10 and x['day'] <= 15)) else 'grejna', axis=1)
df['covid'] = df.apply(lambda x: 'no-covid' if (x['year'] < 2020 or x['year'] > 2021) or (x['year'] == 2020 and x['month'] < 3) or (x['year'] == 2021 and x['month'] > 3) else 'covid', axis=1)
df['zabrana'] = df.apply(lambda x: 'nema-zabrana' if x['year'] < 2020 or (x['year'] == 2020 and x['month'] < 2) or (x['year'] == 2020 and x['month'] == 2 and (x['day'] < 10)) else 'zabrana', axis=1)
df

df['pm25'] = df.loc[:, ['n1-pm25', 'n2-pm25']].mean(axis=1)
df['pm10'] = df.loc[:, ['n1-pm10', 'n2-pm10']].mean(axis=1)
df['co'] = df.loc[:, ['n1-co-mg/m3', 'n3-co-mg/m3']].mean(axis=1)
df['no2'] = df.loc[:, ['n1-no2-ug/m3', 'n2-no2-ug/m3', 'n3-no2-ug/m3']].mean(axis=1)
df

sensors = ['pm25', 'pm10', 'co', 'no2']

def plot_subplots(df, col_name, sensors):
    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    ax = ax.ravel()
    
    for i, sensor in enumerate(sensors):
        chart = df.groupby(col_name)[sensor].mean()
        chart.plot(kind='bar', ax=ax[i], title=f'Sensor {sensor}')
        
    plt.tight_layout()
    plt.show()

plot_subplots(df, 'day-night', sensors)