<jupyter_start><jupyter_text>Exercise 1.02: Create Pandas Series to form a DataFrame 1. Import numpy and pandas package<jupyter_code>import pip
try:
    import numpy 
except ImportError:
     pip.main(['install', 'numpy']) 

try:
    import pandas  
except ImportError:
     pip.main(['install', 'pandas'])<jupyter_output><empty_output><jupyter_text>2. Generate random numbers<jupyter_code>numpy.random.seed(0)
random_number = numpy.random.random(10)

random_number<jupyter_output><empty_output><jupyter_text>3. Set random_number variable to Series and assign it to variable s<jupyter_code>s = pandas.Series(random_number)
print(s)
print(type(s))
print(type(random_number))
print(s[2])<jupyter_output>0.6027633760716439<jupyter_text>4.  Observe what happens when we include an index<jupyter_code>index_value = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
s = pandas.Series(random_number, index=index_value)
print(s)<jupyter_output>a    0.548814
b    0.715189
c    0.602763
d    0.544883
e    0.423655
f    0.645894
g    0.437587
h    0.891773
i    0.963663
j    0.383442
dtype: float64<jupyter_text>Exercise 1.2a:  Create set of lists or Series and stack them as a DataFrame 1. Create four Series of the same lengths<jupyter_code>s1 = pandas.Series([1, 2, 3, 4, 5])
s2 = pandas.Series([6, 7, 8, 9, 10])
s3 = pandas.Series([11, 12, 13, 14, 15])
s4 = pandas.Series([16, 17, 18, 19, 20])<jupyter_output><empty_output><jupyter_text>2. Stack them into DataFrame:<jupyter_code>df = pandas.DataFrame({'s1':s1, 's2':s2, 's3':s3, 's4':s4})
df<jupyter_output><empty_output><jupyter_text>Exercise 3: Download dataset from World Bank Open data to demonstrate how Pandas read file into a DataFrame 1. Use pandas read_csv() to csv file into variable called temp_aus_df<jupyter_code>temp_aus_df =pandas.read_csv("tas_1991_2016_AUS.csv")<jupyter_output><empty_output><jupyter_text>2. Use Pandas head function to print the first few rows of the DataFrame, temp_aus_df<jupyter_code>temp_aus_df.head()<jupyter_output><empty_output><jupyter_text>3. Use Pandas tail function to print the last  few rows of the DataFrame, temp_aus_df<jupyter_code>temp_aus_df.tail()<jupyter_output><empty_output><jupyter_text>4.  What total number of records/rows/observations of the dataframe?<jupyter_code>len(temp_aus_df)<jupyter_output><empty_output><jupyter_text>5. what are the datatypes of the columns in the dataframe?<jupyter_code>temp_aus_df.dtypes<jupyter_output><empty_output><jupyter_text>6. How many missing values in the dataframe?<jupyter_code>temp_aus_df.isnull().sum()<jupyter_output><empty_output><jupyter_text>7. Replace missing values in DataFrame<jupyter_code>for colname in temp_aus_df.columns:
    if  df[colname].dtype == 'object':
        df[colname] =temp_aus_df[colname].fillna('others')
    else:
        temp_aus_df[colname] = temp_aus_df[colname].fillna(0)
temp_aus_df.to_csv(‘newdata.csv’, index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12043671102012965, 'fraction_numerical': 0.05595359945411123, 'mean_word_length': 6.404040404040404, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '115533', 'license': 'MIT', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1125, 'n_words': 248, 'path': 'Chapter01-Python_Overview_and_Main_Packages/Exercise1.02.ipynb', 'repo_name': 'TrainingByPackt/Data-Science-in-Python-the-Simple-Way', 'size': '2931'}