<jupyter_start><jupyter_text>Investor - Flow of Funds - US  Introduction:Special thanks to: https://github.com/rgrp for sharing the dataset. Step 1. Import the necessary libraries<jupyter_code>import pandas as pd
import numpy as np
import datetime

import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
# Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context<jupyter_output><empty_output><jupyter_text>Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/datasets/investor-flow-of-funds-us/master/data/weekly.csv).   Step 3. Assign it to a variable called<jupyter_code>df = pd.read_csv("https://raw.githubusercontent.com/datasets/investor-flow-of-funds-us/master/data/weekly.csv")<jupyter_output><empty_output><jupyter_text>Step 4.  What is the frequency of the dataset?<jupyter_code>df<jupyter_output><empty_output><jupyter_text>Step 5. Set the column Date as the index.<jupyter_code>df.set_index('Date', inplace=True)<jupyter_output><empty_output><jupyter_text>Step 6. What is the type of the index?<jupyter_code>df<jupyter_output><empty_output><jupyter_text>Step 7. Set the index to a DatetimeIndex type<jupyter_code>df.index = df.index.astype('datetime64[ns]')<jupyter_output><empty_output><jupyter_text>Step 8.  Change the frequency to monthly, sum the values and assign it to monthly.<jupyter_code>df = df.resample('M').sum()
(df!=0).any(1)<jupyter_output><empty_output><jupyter_text>Step 9. You will notice that it filled the dataFrame with months that don't have any data with NaN. Let's drop these rows.<jupyter_code>df.loc[(df!=0).any(1)]<jupyter_output><empty_output><jupyter_text>Step 10. Good, now we have the monthly data. Now change the frequency to year.<jupyter_code>df.resample('Y').sum()<jupyter_output><empty_output><jupyter_text>BONUS: Create your own question and answer it.<jupyter_code>df.index[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10566396953831508, 'fraction_numerical': 0.008567348881485007, 'mean_word_length': 7.053639846743295, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 3, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '585432', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 738, 'n_tokens_neox': 711, 'n_words': 165, 'path': '09_Time_Series/Investor_Flow_of_Funds_US/Exercises.ipynb', 'repo_name': 'rishhbhatia/pandas_exercises', 'size': '2101'}