<jupyter_start><jupyter_text>**What is Pandas?**The pandas package is the most important tool at the disposal of Data Scientists and Analysts working in Python today. The powerful machine learning and glamorous visualization tools may get all the attention, but pandas is the backbone of most data projects. **Cheat sheet**http://http://pandas.pydata.org/Pandas_Cheat_Sheet.pdf **A set of lesson for new pandas users**https://bitbucket.org/hrojas/learn-pandas/src/master  **Import libraries**<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>**Read dataset**<jupyter_code>df = pd.read_csv('../input/pokemon/Pokemon.csv')<jupyter_output><empty_output><jupyter_text>**Print the dataset**<jupyter_code>df<jupyter_output><empty_output><jupyter_text>**Count total rows**<jupyter_code>print(str(len(df)))<jupyter_output>800<jupyter_text>**Print first five row**<jupyter_code>df.head(5)<jupyter_output><empty_output><jupyter_text>**Print last five rows**<jupyter_code>df.tail(5)<jupyter_output><empty_output><jupyter_text>**Read data size**<jupyter_code>df.shape<jupyter_output><empty_output><jupyter_text>**Read headers**<jupyter_code>df.columns<jupyter_output><empty_output><jupyter_text>**Check the types of each column**<jupyter_code>df.dtypes<jupyter_output><empty_output><jupyter_text>**Read each Columns**<jupyter_code>df['Name']<jupyter_output><empty_output><jupyter_text>**Read first five names**<jupyter_code>df['Name'][0:5]
df[['Name', 'Generation', 'Speed']]<jupyter_output><empty_output><jupyter_text>**Read each row**<jupyter_code>df.iloc[1]
df.iloc[543]<jupyter_output><empty_output><jupyter_text>**Read multiple rows**<jupyter_code>df.iloc[9:12]<jupyter_output><empty_output><jupyter_text>**Read a specific a value**<jupyter_code>df.iloc[10,5]
df.iloc[9,2]<jupyter_output><empty_output><jupyter_text>**Read rows using condition**<jupyter_code>df.loc[df['Type 1'] == 'Water']<jupyter_output><empty_output><jupyter_text>**Read rows using multiple condition**<jupyter_code>df.loc[(df['Type 1'] == 'Water') & (df['Type 2'] == 'Dark')]
df.loc[(df['Type 1'] == 'Water') & (df['Type 2'] == 'Dark') & (df['HP'] > 60)]
array = ['Dark', 'Ghost', 'Ground']
df.loc[(df['Type 1'] == 'Fire') & df['Type 2'].isin(array)]
array = ['Fire', 'Water', 'Rain']
df.loc[df['Type 1'].isin(array)]<jupyter_output><empty_output><jupyter_text>**Describing data**<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>**Sorting data**<jupyter_code>df.sort_values('Name')<jupyter_output><empty_output><jupyter_text>**Sorting data using multiple columns**<jupyter_code>df.sort_values(['Name', 'HP', 'Generation'])<jupyter_output><empty_output><jupyter_text>**Sorting data into dscending order**<jupyter_code>df.sort_values('Name', ascending = False)
df.sort_values(['Name', 'Type 1', 'Type 2'], ascending = [1, 0, 1])<jupyter_output><empty_output><jupyter_text>**Making changes to the data**<jupyter_code>df.head(5)
df['Sum'] = df['Total'] + df['HP'] + df['Attack']
df.head(5)
df['Mul'] = df['HP'] * df['Attack']
df.tail(5)<jupyter_output><empty_output><jupyter_text>**Drop a column**<jupyter_code>df.columns
df = df.drop(columns=['Sum'])
df.head(3)<jupyter_output><empty_output><jupyter_text>**Alternative way to sum columns**<jupyter_code>df['Sum2'] = df.iloc[:, 4:8].sum(axis=1)
df.head(3)<jupyter_output><empty_output><jupyter_text>**Drop multiple columns**<jupyter_code>df = df.drop(columns=['Sum2', 'Mul'])
df.head(5)<jupyter_output><empty_output><jupyter_text>**Filtering data** **Sreach rows using valus**<jupyter_code>df.loc[df['Type 1'] == 'Dark']
df.loc[df['Type 2'] == 'Fire']<jupyter_output><empty_output><jupyter_text>**Search rows using multiple values**<jupyter_code>df.loc[(df['Type 1'] == 'Bug') & (df['Type 2'] == 'Fire')]
df.loc[(df['Type 1'] == 'Dark') & (df['Type 2'] == 'Fire') & (df['HP'] > 20)]
df.loc[((df['Type 1'] == 'Dark') | (df['Type 2'] == 'Dark')) & (df['Total'] > 500)]<jupyter_output><empty_output><jupyter_text>**Making new csv file**<jupyter_code>df_new = df.loc[(df['Type 1'] == 'Dark') & (df['Type 2'] == 'Fire') & (df['HP'] > 10)]
df_new
#df_new.to_csv('New Pokemon')
df_new1 = df.loc[(df['Type 1'] == 'Dark') | (df['Defense'] >= 600)]
df_new1<jupyter_output><empty_output><jupyter_text>**Searchibg by string values**<jupyter_code>df.loc[df['Name'].str.contains('Houndoom')]
df.loc[df['Name'].str.contains('ye')]
df.loc[df['Name'].str.contains('Sableye') & (df['Total'] > 390)]
df.loc[df['Name'].str.contains('Houndoom')]
df.loc[~df['Name'].str.contains('Houndoom')][0:5]
import re
df.loc[df['Type 1'].str.contains('Grass|Ghost', regex = True)]
df.loc[df['Type 1'].str.contains('poison|flying', flags = re.I, regex=True)]<jupyter_output><empty_output><jupyter_text>**Conditional changes**<jupyter_code>df.head(5)
df.loc[df['Type 1'] == 'Grass', 'Type 1'] = 'Poison'
df.head(5)
df.loc[df['Type 1'] == 'Poison', 'Type 1'] = 'Grass'
df.head(5)
df.loc[df['HP'] >= 50, ['Total', 'Attack']] = 'Test0'
df.head(5)
df.loc[df['Total'] == 'Test0', ['Total', 'Attack']] = [12, 45]
df.head(5)
df.loc[df['Total'] == 12, ['Total', 'Attack']] = [2, 5]
df.head(5)<jupyter_output><empty_output><jupyter_text>**Group by - mean**<jupyter_code>df.groupby('Type 1').mean()
df.groupby('Type 1').mean().sort_values('HP', ascending = False)
df.groupby('Type 2').mean().sort_values('Attack', ascending = False)<jupyter_output><empty_output><jupyter_text>**Group by - sum**<jupyter_code>df.groupby('Type 1').sum()<jupyter_output><empty_output><jupyter_text>**Group by - count**<jupyter_code>df.groupby('Type 1').count()
df['Count'] = 1
df.groupby(['Type 1']).count()['Count']
df['Count'] = 1
df.groupby(['Type 1', 'Type 2']).count()['Count']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21836663161584297, 'fraction_numerical': 0.018752190676480898, 'mean_word_length': 10.103112840466926, 'pattern_counts': {'":': 0, '<': 128, '<?xml version=': 0, '>': 135, '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': '32', 'dir': 'jupyter-structured-clean-dedup', 'id': '658594', 'license': 'Apache-2.0', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2281, 'n_words': 325, 'path': 'learn-python-pandas-using-pokemon-dataset.ipynb', 'repo_name': 'rashidulhasanhridoy/Learn-Python-Pandas-using-Pokemon-Dataset-', 'size': '5706'}