<jupyter_start><jupyter_text>Data Cleaning - River Ganga Dataset Importing necessary libraries<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Reading the dataset<jupyter_code>#Ganga_data
df = pd.read_csv('Ganga.csv')
df<jupyter_output><empty_output><jupyter_text>Replacing negative values with NaN<jupyter_code>num = df._get_numeric_data()
num[num<0] = np.nan
df<jupyter_output><empty_output><jupyter_text>Replacing NaN values in the attributes with the mean of the last 5 values<jupyter_code>do = df['DO']
do
for i in range(len(do)):
    if i>5:
        if np.isnan(do[i]):
                do[i] = np.mean([do[i-1], do[i-2], do[i-3], do[i-4], do[i-5]])
do
for i in range(4,-1,-1):
    if np.isnan(do[i]):
            do[i] = np.mean([do[i+1], do[i+2], do[i+3], do[i+4], do[i+5]])
do
df.isnull().sum()
orp = df['ORP']
orp
for i in range(len(orp)):
    if i>5:
        if np.isnan(orp[i]):
                orp[i] = np.mean([orp[i-1], orp[i-2], orp[i-3], orp[i-4], orp[i-5]])
orp
df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Converting to csv file<jupyter_code>df.to_csv('Ganga_data.csv', index = False)
#Sangam_data
#sdf = pd.read_csv('Sangam.csv')
#sdf
#n = sdf._get_numeric_data()
#n[n<0] = np.nan
#sdf.isnull().sum()
#do = sdf['DO']
#for i in range(len(do)):
    #if i>5:
        #if np.isnan(do[i]):
                #do[i] = np.mean([do[i-1], do[i-2], do[i-3], do[i-4], do[i-5]])
#for i in range(4,-1,-1):
    #if np.isnan(do[i]):
            #do[i] = np.mean([do[i+1], do[i+2], do[i+3], do[i+4], do[i+5]])
#orp = sdf['ORP']
#for i in range(len(orp)):
    #if i>5:
        #if np.isnan(orp[i]):
                #orp[i] = np.mean([orp[i-1], orp[i-2], orp[i-3], orp[i-4], orp[i-5]])
#sdf.to_csv('Sangam_data.csv', index = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21393307734503567, 'fraction_numerical': 0.023587493143170598, 'mean_word_length': 3.9297297297297296, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '29799', 'license': 'Apache-2.0', 'n_tokens_mistral': 848, 'n_tokens_neox': 832, 'n_words': 152, 'path': '3_Data_Cleaning.ipynb', 'repo_name': 'Shivani-781/Ganga-Water-Quality-Assessment', 'size': '1823'}