<jupyter_start><jupyter_text>Wine  Introduction:This exercise is a adaptation from the UCI Wine dataset.The only pupose is to practice deleting data with pandas. Step 1. Import the necessary libraries<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Step 2. Import the dataset from this [address](https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data).   Step 3. Assign it to a variable called wine<jupyter_code>url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data'
df = pd.read_csv(url, header=None)
df.head()<jupyter_output><empty_output><jupyter_text>Step 4. Delete the first, fourth, seventh, nineth, eleventh, thirteenth and fourteenth columns<jupyter_code>df = df.drop(columns=df.columns[[0,3,6,8,10,12,13]])
df.head()<jupyter_output><empty_output><jupyter_text>Step 5. Assign the columns as below:The attributes are (donated by <NAME>, riclea '@' anchem.unige.it):  1) alcohol  2) malic_acid  3) alcalinity_of_ash  4) magnesium  5) flavanoids  6) proanthocyanins  7) hue<jupyter_code>new_names = ['alcohol', 'malic_acid', 'alcalinity_of_ash',
             'magnesium', 'flovonoids', 'proanthocyanins', 'hue']
my_dict = dict(zip(df.columns.values, new_names))
df = df.rename(columns=my_dict)
df.head()<jupyter_output><empty_output><jupyter_text>Step 6. Set the values of the first 3 rows from alcohol as NaN<jupyter_code>df.loc[0:2,'alcohol'] = np.nan
df.head()<jupyter_output><empty_output><jupyter_text>Step 7. Now set the value of the rows 3 and 4 of magnesium as NaN<jupyter_code>df.loc[2:3,'magnesium'] = np.nan
df.head()<jupyter_output><empty_output><jupyter_text>Step 8. Fill the value of NaN with the number 10 in alcohol and 100 in magnesium<jupyter_code>df = df.fillna(value={'alcohol':10, 'magnesium':100})
df.head()<jupyter_output><empty_output><jupyter_text>Step 9. Count the number of missing values<jupyter_code>df.isna().sum()<jupyter_output><empty_output><jupyter_text>Step 10.  Create an array of 10 random numbers up until 10<jupyter_code>arr = np.random.randint(1,11,10)
arr<jupyter_output><empty_output><jupyter_text>Step 11.  Use random numbers you generated as an index and assign NaN value to each of cell.<jupyter_code># for i in arr:
#     df.loc[i,:]=np.nan
df.iloc[arr]=np.nan
df.head()<jupyter_output><empty_output><jupyter_text>Step 12.  How many missing values do we have?<jupyter_code>df.isna().sum().sum()<jupyter_output><empty_output><jupyter_text>Step 13. Delete the rows that contain missing values<jupyter_code>df = df.dropna(how='any', axis='rows')
df.head()<jupyter_output><empty_output><jupyter_text>Step 14. Print only the non-null values in alcohol<jupyter_code>for x in list(df[df.notna()]['alcohol']):
    print(x, end=' | ')<jupyter_output>10.0 | 10.0 | 14.37 | 13.86 | 14.12 | 13.75 | 14.75 | 14.38 | 13.63 | 14.3 | 13.83 | 14.19 | 13.64 | 14.06 | 12.93 | 13.71 | 12.85 | 13.5 | 13.05 | 13.39 | 13.3 | 13.87 | 14.02 | 13.73 | 13.58 | 13.68 | 13.76 | 13.51 | 13.48 | 13.28 | 13.05 | 13.07 | 14.22 | 13.56 | 13.41 | 13.88 | 13.24 | 13.05 | 14.21 | 14.38 | 13.9 | 14.1 | 13.94 | 13.05 | 13.83 | 13.82 | 13.77 | 13.74 | 13.56 | 14.22 | 13.29 | 13.72 | 12.37 | 12.33 | 12.64 | 13.67 | 12.37 | 12.17 | 12.37 | 13.11 | 12.37 | 13.34 | 12.21 | 12.29 | 13.86 | 13.49 | 12.99 | 11.96 | 11.66 | 13.03 | 11.84 | 12.33 | 12.7 | 12.0 | 12.72 | 12.08 | 13.05 | 11.84 | 12.67 | 12.16 | 11.65 | 11.64 | 12.08 | 12.08 | 12.0 | 12.69 | 12.29 | 11.62 | 12.47 | 11.81 | 12.29 | 12.37 | 12.29 | 12.08 | 12.6 | 12.34 | 11.82 | 12.51 | 12.42 | 12.25 | 12.72 | 12.22 | 11.61 | 11.46 | 12.52 | 11.76 | 11.41 | 12.08 | 11.03 | 11.82 | 12.42 | 12.77 | 12.0 | 11.45 | 11.56 | 12.42 | 13.05 | 11.87 | 12.07 | 12.43 | 11.79 | 12.37 | 12.04 | 12.86 | 12.88 | 12.81 | 12.7[...]<jupyter_text>Step 15.  Reset the index, so it starts with 0 again<jupyter_code>df = df.reset_index(drop=True)
df.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1622651091924835, 'fraction_numerical': 0.14220416455053325, 'mean_word_length': 4.182894736842106, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '550412', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1589, 'n_words': 374, 'path': '10_Deleting/Wine/Exercises.ipynb', 'repo_name': 'SmellyArmure/SmellyArmure', 'size': '3947'}