<jupyter_start><jupyter_text>Copyright 2020 Catalit LLC.<jupyter_code># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.<jupyter_output><empty_output><jupyter_text>Documentation links:- [Google Colab](https://colab.research.google.com/notebooks/intro.ipynb)- [Numpy](https://docs.scipy.org/doc/)- [Pandas](https://pandas.pydata.org/docs/getting_started/index.html)- [Pandas Cheatsheet](https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf)- [Matplotlib](https://matplotlib.org/)- [Matplotlib Cheat Sheet](https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Python_Matplotlib_Cheat_Sheet.pdf)- [Seaborn](https://seaborn.pydata.org/)- [Scikit-learn](https://scikit-learn.org/stable/user_guide.html)- [Scikit-learn Cheat Sheet](https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Scikit_Learn_Cheat_Sheet_Python.pdf)- [Scikit-learn Flow Chart](https://scikit-learn.org/stable/tutorial/machine_learning_map/index.html)  Pandas Matplotlib Seaborn<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Google ColabColaboratory is an online environment that allows you to write and execute Python in the browser.- Zero configuration required- Free access to GPUs and TPUs- Easy sharingIt's based on [Jupyter Notebook](https://jupyter.org/)If you've never used it before it's a good idea to read the [tutorial here](https://colab.research.google.com/notebooks/intro.ipynb).  Keyboard shortcutsHere are some of the most common commands. Try them out:- `⌘/Ctrl+M H` => open the keyboard shortcut help- `⌘/Ctrl+M A` => Create a cell above- `⌘/Ctrl+M B` => Create a cell below- `⌘/Ctrl+M D` => Delete current cell- `⌘/Ctrl+M M` => Convert cell to Markdown- `⌘/Ctrl+M Y` => Convert cell to Code- `Shift+Enter` => Run cell and select next cell- `Ctrl+Space`, `Option+Esc` or `Tab` => Autocomplete  Saving your work- Colab notebooks are automatically saved in your Google Drive- You can export them to Github too- You can download them to your local computer  PandasPandas is an open source library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Let's explore some of its functionality together.  Reading and exploring data<jupyter_code>url = "https://raw.githubusercontent.com/zerotodeeplearning/ztdl-masterclasses/master/data/"
df = pd.read_csv(url + "titanic-train.csv")
df.head()
df.info()
df.describe()<jupyter_output><empty_output><jupyter_text>PlottingMatplotlib and Seaborn are great libraries for plotting and exploring data visually.You can take inspiration from their plot galleries:- [Matplotlib Gallery](https://matplotlib.org/3.2.1/gallery/index.html)- [Seaborn Gallery](https://seaborn.pydata.org/examples/index.html)<jupyter_code>df[['Age', 'Fare']].plot.scatter(x='Age', y='Fare');
survived_counts = df['Survived'].value_counts()
survived_counts.plot.bar(title='Dead / Survived');
survived_counts.plot.pie(
    figsize=(5, 5),
    explode=[0, 0.15],
    labels=['Dead', 'Survived'],
    autopct='%1.1f%%',
    shadow=True,
    startangle=90,
    fontsize=16);
df['Age'].plot.hist(
    bins=16,
    range=(0, 80),
    title='Passenger age distribution')
plt.xlabel("Age");
sns.pairplot(df[['Age', 'Pclass', 'Fare', 'SibSp', 'Survived']],
             hue='Survived');
sns.jointplot(x='Age', y='Fare', data=df)<jupyter_output><empty_output><jupyter_text>IndexingRetrieving elements by row, by column or both. Try to understand each of the following statements<jupyter_code>df['Ticket']
df[['Fare', 'Ticket']]
df.iloc[3]
df.iloc[0:4, 4:6]
df.loc[0:4, 'Ticket']
df.loc[0:4, ['Fare', 'Ticket']]<jupyter_output><empty_output><jupyter_text>SelectionsRetrieving part of the dataframe based on a condition. Try to understand each of the following statements.<jupyter_code>df[df.Age > 70]
df[(df['Age'] == 11) & (df['SibSp'] == 5)]<jupyter_output><empty_output><jupyter_text>Distinct elements<jupyter_code>df['Embarked'].unique()<jupyter_output><empty_output><jupyter_text>Group-by & Sorting<jupyter_code># Find average age of passengers that survived vs. died
df.groupby('Survived')['Age'].mean()
df.sort_values('Age', ascending = False).head()<jupyter_output><empty_output><jupyter_text>Join (merge)<jupyter_code>df1 = df[['PassengerId', 'Survived']]
df2 = df[['PassengerId', 'Age']]

pd.merge(df1, df2, on='PassengerId').head()<jupyter_output><empty_output><jupyter_text>Pivot Tables<jupyter_code>df.pivot_table(index='Pclass', columns='Survived', values='PassengerId', aggfunc='count')
df['Pclass'].value_counts()<jupyter_output><empty_output><jupyter_text>Time series data<jupyter_code>dfts = pd.read_csv(url + 'time_series_covid19_confirmed_global.csv')
df1 = dfts.drop(['Lat', 'Long'], axis=1).groupby('Country/Region').sum().transpose()
df1.head()
df1.index.dtype
df1.index = pd.to_datetime(df1.index)
df1.index.dtype
df1[['Italy','US']].plot(logy=True)
plt.title("COVID-19 confirmed Cases");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14535838044865948, 'fraction_numerical': 0.010942914462885282, 'mean_word_length': 6.2348284960422165, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 54, 'https://': 16, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '52165', 'license': 'Apache-2.0', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1890, 'n_words': 437, 'path': 'notebooks/Pandas_Matplotlib_Seaborn.ipynb', 'repo_name': 'KyleWendt/ztdl-masterclasses', 'size': '5483'}