<jupyter_start><jupyter_text>Deletingimport dataset from https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data<jupyter_code>import pandas as pd
import numpy as np
df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data')
df<jupyter_output><empty_output><jupyter_text>Delete the first, fourth, seventh, nineth, eleventh, thirteenth and fourteenth columns<jupyter_code>df = df.drop(df.columns[[0, 3, 6, 8, 11, 12, 13]], axis = 1)
df
df.columns = ['alcohol', 'malic_acid', 'alcalinity_of_ash', 'magnesium', 'flavanoids', 'proanthocyanins', 'hue'] 
df.head()<jupyter_output><empty_output><jupyter_text>Set the values of the first 3 rows from alcohol as NaN<jupyter_code>df.iloc[0:3, 0] = np.nan
df<jupyter_output><empty_output><jupyter_text>Set the value of the rows 3 and 4 of magnesium as NaN<jupyter_code>df.iloc[2:4, 3] = np.nan
df<jupyter_output><empty_output><jupyter_text>Fill the value of NaN with the number 10 in alcohol and 100 in magnesium<jupyter_code>df.alcohol.fillna(10, inplace = True)
df.magnesium.fillna(100, inplace = True)
df<jupyter_output><empty_output><jupyter_text>Count the number of missing values<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Create an array of 10 random numbers up until 10<jupyter_code>random = np.random.randint(10, size = 10)
random<jupyter_output><empty_output><jupyter_text>Use random numbers you generated as an index and assign NaN value to each of cell<jupyter_code>df.alcohol[random] = np.nan
df.head(10)<jupyter_output><empty_output><jupyter_text>How many missing values do we have?<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Delete the rows that contain missing values<jupyter_code>df = df.dropna(axis = 0, how = 'any')
df<jupyter_output><empty_output><jupyter_text>Print only the non-null values in alcohol<jupyter_code>mask = df.alcohol.notnull()
mask
df.alcohol[mask]<jupyter_output><empty_output><jupyter_text>Reset the index, so it starts with 0 again<jupyter_code>df = df.reset_index(drop = True)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12232270347453593, 'fraction_numerical': 0.019990480723465015, 'mean_word_length': 7.982905982905983, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 2, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '619265', 'license': 'MIT', 'n_tokens_mistral': 836, 'n_tokens_neox': 781, 'n_words': 164, 'path': 'DataTalks_Deleting II.ipynb', 'repo_name': 'gympohnpimol/Pandas-Data-Talks', 'size': '2101'}