<jupyter_start><jupyter_text>Pandas https://pandas.pydata.org/10 Minutes to pandashttp://pandas.pydata.org/pandas-docs/stable/10min.htmlTutorialshttp://pandas.pydata.org/pandas-docs/stable/tutorials.html<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>**Series**<jupyter_code># pd.Series( data = [ ] , index = [ ] )

ser1 = pd.Series( [10, 20, 30] )
ser1
ser1.index = ['a', 'b', 'c']
ser1
ser2 = pd.Series( {'a':100, 'b':200, 'c':300} )
ser2
ser3 = pd.Series( [1, 2, 3, 4], index = ['USA', 'Germany', 'France', 'Japan'] )
ser3
ser4 = pd.Series( [1, 2, 5, 4], index = ['USA', 'Germany', 'Italy', 'Japan'] )
ser4
ser3 + ser4<jupyter_output><empty_output><jupyter_text>**DataFrame**<jupyter_code># pd.DataFrame( data = [ ], index = [ ], columns = [ ] )
df = pd.read_csv( 'gapminder.csv', index_col = 'Unnamed: 0' )
df.head()
df['income'][:5]
df['gross_income'] = df['income'] * df['population']
df.head()
df.drop( labels = 'gross_income', axis = 1, inplace = True )
df.head()<jupyter_output><empty_output><jupyter_text>Selecting rows and columns<jupyter_code>df.loc[3]
df.loc[ 5, 'country' ]
df.loc[ [ 10, 100, 1000 ], ['continent', 'country'] ]<jupyter_output><empty_output><jupyter_text>Conditional Selection<jupyter_code>df[ df['income'] > 50000 ]
# multiple conditions : & (and) , | (or)
df[  ( df['income'] > 50000 ) & ( df['life_exp'] > 80 )  ]<jupyter_output><empty_output><jupyter_text>Setting and resetting indices<jupyter_code>df.set_index('year')
df.dropna().reset_index()<jupyter_output><empty_output><jupyter_text>Missing Data<jupyter_code>df['income'].fillna( value = 0 )<jupyter_output><empty_output><jupyter_text>Groupby<jupyter_code>by_year = df.groupby('year')
by_year
by_year.mean().tail()
by_year.describe().tail()
by_year.describe()[ 'income' ]<jupyter_output><empty_output><jupyter_text>Multi-Index and Index Hierarchy<jupyter_code>outside = df['year']
inside = df['continent']
asia_df = df[ df['continent'] == 'asia' ]
amer_df = df[ df['continent'] == 'americas' ]
eur_df = df[ df['continent'] == 'europe' ]
afr_df = df[ df['continent'] == 'africa' ]
asia_df.groupby( by = 'year' ).mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.030205949656750573, 'mean_word_length': 6.891696750902527, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 40, 'https://': 1, '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': '512027', 'license': 'MIT', 'n_tokens_mistral': 956, 'n_tokens_neox': 886, 'n_words': 149, 'path': 'python/pandas/1-pandas-Series-DataFrame.ipynb', 'repo_name': 'skawns0724/KOSA-Big-Data_Vision', 'size': '2185'}