<jupyter_start><jupyter_text>Creating a test dataframe by duplicating df<jupyter_code>df1 = copy.deepcopy(df)
df1<jupyter_output><empty_output><jupyter_text>Adding a single column<jupyter_code>df1["cities"]  = pd.Series([["Nairobi", "Mombasa"], ["Lagos", "Nigeria"], ["Cape Town", "Johannesburg"]])<jupyter_output><empty_output><jupyter_text>Adding multiple columns using the assign function<jupyter_code>df1 = df1.assign(
    adult_viewers = pd.Series([500000, 1000000, 750000]),
    aged_viewers = pd.Series([200000, 400000, 300000]),
    young_viewers = pd.Series([1000000, 2000000, 3500000])
)
df1<jupyter_output><empty_output><jupyter_text>To add a new row we use the append function<jupyter_code>df1 = df1.append(
    {
        'cities': ["Kolkata", "Hyderabad"],
        'adult_viewers': 2000000,
        'aged_viewers': 2000000,
        'young_viewers': 1500000
    },
    ignore_index =True
 )
df1.head()<jupyter_output><empty_output><jupyter_text>To duplicate df1 and concatenate<jupyter_code>df2 = pd.concat([df1, df1], sort=False)
df2<jupyter_output><empty_output><jupyter_text>To delete a row:<jupyter_code>df1 = df1.drop([3])
df1<jupyter_output><empty_output><jupyter_text>To delete a column:<jupyter_code>df1 = df1.drop(["aged_viewers"], axis=1)
df1<jupyter_output><empty_output><jupyter_text>We can chain functions as follows(dropping the cities column and dropping duplicates)<jupyter_code>df2 = df2.drop(["cities"], axis=1).drop_duplicates()
df2<jupyter_output><empty_output><jupyter_text>Performing operations on the dataframe<jupyter_code>df2 = df2.fillna(df2.mean())
df2
df2["viewers"] = df2["adult_viewers"] + df2["aged_viewers"] + df2["young_viewers"]
df2
df2["expected_clicks"] = 0.03*df2["viewers"]
df2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1439954467842914, 'fraction_numerical': 0.06829823562891292, 'mean_word_length': 7.702970297029703, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '566448', 'license': 'MIT', 'n_tokens_mistral': 763, 'n_tokens_neox': 682, 'n_words': 108, 'path': 'Lesson01/Exercise 3.ipynb', 'repo_name': 'FelixOnduru1/Data-Science-for-Marketing-Analytics', 'size': '1757'}