text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

Aquifer_Doganella = pd.read_csv('/kaggle/input/acea-water-prediction/Aquifer_Doganella.csv')
Aquifer_Auser = pd.read_csv('/kaggle/input/acea-water-prediction/Aquifer_Auser.csv')
Water_Spring_Amiata = pd.read_csv('/kaggle/input/acea-water-prediction/Water_Spring_Amiata.csv')
Lake_Bilancino = pd.read_csv('/kaggle/input/acea-water-prediction/Lake_Bilancino.csv')
Water_Spring_Madonna_di_Canneto = pd.read_csv('/kaggle/input/acea-water-prediction/Water_Spring_Madonna_di_Canneto.csv')
Aquifer_Luco = pd.read_csv('/kaggle/input/acea-water-prediction/Aquifer_Luco.csv')
Aquifer_Petrignano = pd.read_csv('/kaggle/input/acea-water-prediction/Aquifer_Petrignano.csv')
Water_Spring_Lupa = pd.read_csv('/kaggle/input/acea-water-prediction/Water_Spring_Lupa.csv')
River_Arno = pd.read_csv('/kaggle/input/acea-water-prediction/River_Arno.csv')
Aquifer_Doganella['Date'] = pd.to_datetime(Aquifer_Doganella['Date'])
Aquifer_Auser['Date'] = pd.to_datetime(Aquifer_Auser['Date'])
Water_Spring_Amiata['Date'] = pd.to_datetime(Water_Spring_Amiata['Date'])
Lake_Bilancino['Date'] = pd.to_datetime(Lake_Bilancino['Date'])
Water_Spring_Madonna_di_Canneto['Date'] = pd.to_datetime(Water_Spring_Madonna_di_Canneto['Date'])
Aquifer_Luco['Date'] = pd.to_datetime(Aquifer_Luco['Date'])
Aquifer_Petrignano['Date'] = pd.to_datetime(Aquifer_Petrignano['Date'])
Water_Spring_Lupa['Date'] = pd.to_datetime(Water_Spring_Lupa['Date'])
River_Arno['Date'] = pd.to_datetime(River_Arno['Date'])

def get_datefeatures(df):
    df['month'] = df.Date.dt.month
    df['day'] = df.Date.dt.day
    df['week'] = df.Date.dt.week
    df['year'] = df.Date.dt.year
    return df
Aquifer_Doganella = get_datefeatures(df=Aquifer_Doganella)
Aquifer_Auser = get_datefeatures(df=Aquifer_Auser)
Water_Spring_Amiata = get_datefeatures(df=Water_Spring_Amiata)
Lake_Bilancino = get_datefeatures(df=Lake_Bilancino)
Water_Spring_Madonna_di_Canneto = get_datefeatures(df=Water_Spring_Madonna_di_Canneto)
Aquifer_Luco = get_datefeatures(df=Aquifer_Luco)
Aquifer_Petrignano = get_datefeatures(df=Aquifer_Petrignano)
Water_Spring_Lupa = get_datefeatures(df=Water_Spring_Lupa)
River_Arno = Water_Spring_Lupa = get_datefeatures(df=River_Arno)

def check_duplicates(df, df_name):
    pass
check_duplicates(df=Aquifer_Doganella, df_name='Aquifer_Doganella')
check_duplicates(df=Aquifer_Auser, df_name='Aquifer_Auser')
check_duplicates(df=Water_Spring_Amiata, df_name='Water_Spring_Amiata')
check_duplicates(df=Lake_Bilancino, df_name='Lake_Bilancino')
check_duplicates(df=Water_Spring_Madonna_di_Canneto, df_name='Water_Spring_Madonna_di_Canneto')
check_duplicates(df=Aquifer_Luco, df_name='Aquifer_Luco')
check_duplicates(df=Aquifer_Petrignano, df_name='Aquifer_Petrignano')
check_duplicates(df=Water_Spring_Lupa, df_name='Water_Spring_Lupa')
check_duplicates(df=River_Arno, df_name='River_Arno')

def find_total_missing_days(df, df_name):
    daily_date = pd.date_range(start=df.Date.min(), end=df.Date.max(), freq='D')
    uniq_days = df.Date.nunique()
find_total_missing_days(df=Aquifer_Doganella, df_name='Aquifer_Doganella')
find_total_missing_days(df=Aquifer_Auser, df_name='Aquifer_Auser')
find_total_missing_days(df=Water_Spring_Amiata, df_name='Water_Spring_Amiata')
find_total_missing_days(df=Lake_Bilancino, df_name='Lake_Bilancino')
find_total_missing_days(df=Water_Spring_Madonna_di_Canneto, df_name='Water_Spring_Madonna_di_Canneto')
find_total_missing_days(df=Aquifer_Luco, df_name='Aquifer_Luco')
find_total_missing_days(df=Aquifer_Petrignano, df_name='Aquifer_Petrignano')
find_total_missing_days(df=Water_Spring_Lupa, df_name='Water_Spring_Lupa')
find_total_missing_days(df=River_Arno, df_name='River_Arno')

def total_missing_days_pattern(df, df_name):
    daily_date = pd.date_range(start=df.Date.min(), end=df.Date.max(), freq='D')
    daily_data = pd.DataFrame({'Date': daily_date})
    temp = df[['Date']].copy()
    temp['missing'] = 0
    final = daily_data.merge(temp, on=['Date'], how='left')
    final.fillna(1, inplace=True)
total_missing_days_pattern(df=Aquifer_Doganella, df_name='Aquifer_Doganella')
total_missing_days_pattern(df=Aquifer_Auser, df_name='Aquifer_Auser')
total_missing_days_pattern(df=Water_Spring_Amiata, df_name='Water_Spring_Amiata')
total_missing_days_pattern(df=Lake_Bilancino, df_name='Lake_Bilancino')
total_missing_days_pattern(df=Water_Spring_Madonna_di_Canneto, df_name='Water_Spring_Madonna_di_Canneto')
total_missing_days_pattern(df=Aquifer_Luco, df_name='Aquifer_Luco')
total_missing_days_pattern(df=Aquifer_Petrignano, df_name='Aquifer_Petrignano')
total_missing_days_pattern(df=Water_Spring_Lupa, df_name='Water_Spring_Lupa')
total_missing_days_pattern(df=River_Arno, df_name='River_Arno')

def Null_analysis(df, title):
    temp = df.isnull().sum()
    plt.figure(figsize=(15, 5))
    g = sns.barplot(temp.index, temp.values)
    plt.xticks(rotation=90)
    plt.ylim(0, temp.values.max() + 1000)
    plt.title(title)
    for p in g.patches:
        g.annotate('{:.0f}\n{:.2f}%'.format(p.get_height(), p.get_height() / df.shape[0]), (p.get_x() + 0.4, p.get_height() + 10), ha='center', va='bottom', color='black')
    plt.show()
Null_analysis(df=Aquifer_Doganella, title='Aquifer_Doganella')
Null_analysis(df=Aquifer_Auser, title='Aquifer_Auser')
Null_analysis(df=Water_Spring_Amiata, title='Water_Spring_Amiata')
Null_analysis(df=Lake_Bilancino, title='Lake_Bilancino')
Null_analysis(df=Water_Spring_Madonna_di_Canneto, title='Water_Spring_Madonna_di_Canneto')
Null_analysis(df=Aquifer_Luco, title='Aquifer_Luco')
Null_analysis(df=Aquifer_Petrignano, title='Aquifer_Petrignano')
Null_analysis(df=Water_Spring_Lupa, title='Water_Spring_Lupa')
Null_analysis(df=River_Arno, title='River_Arno')