<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Jupyter Notebooks
Major features
Online environment for running snippets
Combine hypertext, code and charts on the same page
Perfect for sharing snippets for teach something to others.
Don't need to have a local environment with all the languages and libs
Language support
Multiple languages are supported through the concept of kernels
Step1:  Example 2
<ASSISTANT_TASK:>
Python Code:
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
# Make charts a bit prettier
plt.style.use('ggplot')
titanic = pd.read_csv('titanic.csv', sep = ',')
# What are the dimensions
titanic.shape
# What are the column names
titanic.columns
titanic['MySum'] = titanic["Survived"] + titanic["Pclass"]
# What do the first few rows look like
titanic.head()
# Let's x cleanup the data a bit
city_names =  {"C": "Cherbourg", "Q": "Queenstown", "S": "Southampton"} 
titanic["EmbarkedCode"] = titanic["Embarked"]
titanic["Embarked"] = titanic["EmbarkedCode"].apply(lambda value: city_names.get(value)) 
# Check if it worked
titanic.head()
#Tell matplotlib to render graphs inside this notebook
%matplotlib inline
# Let's create a contingency table
pd.crosstab(titanic.Pclass, titanic.Survived, margins = True) 
# Let's do the same but as percentages
pd.crosstab(titanic.Pclass, titanic.Survived, margins = True).apply(lambda row: row/len(titanic))
titanic.groupby(["Sex", "Survived"]).count().unstack("Survived")["PassengerId"]
# Let's create a stacked bar chart for sex vs. survivability 
titanic.groupby(["Sex", "Survived"]).count().unstack("Survived")["PassengerId"].plot(kind="bar", stacked=True)
titanic[titanic.Sex == 'female']
# Do the same graph, but only for people older than 18 years old
titanic[titanic.Age >= 18].groupby(["Sex", "Survived"]).count().unstack("Survived")["PassengerId"].plot(kind="bar", stacked=True)
Explanation: Jupyter Notebooks
Major features
Online environment for running snippets
Combine hypertext, code and charts on the same page
Perfect for sharing snippets for teach something to others.
Don't need to have a local environment with all the languages and libs
Language support
Multiple languages are supported through the concept of kernels: interpreters that execute tiny scripts one by one, on demand, while maintaining a runtime environment. Basically a REPL that's called from the web UI. The list currently includes:
* Python
* R
* F# (on Azure Notebooks)a
* Julia/Scala/etc.
Data Science / Machine Learning
Python and R are also popular for data science and machine learning, so people made sure they integrate well with Jupyter Notebooks. This means that many objects render nicely on the Notebook UI:
Pandas DataFrames are rendered as tables
matplotlib charts are rendered as inline pictures
Scientific Python
For machine learning, 3 types of libraries always pop up:
* Data Analysis: These are libraries that can load data from various sources, do various transformations, and compute basic statistics. Best Python example: Pandas
* Machine Learning: These libraries implement machine learning algorithms. Best Python example: scikit-learn
* Charting: Render various graphs and plots of our data. Best Python example: matplotlib
Example 1: Titanic dataset
End of explanation
games = pd.read_csv("videogames.csv", sep = ",")
games.head()
by_publisher = games.groupby("Publisher").agg({"NA_Sales": sum, 
                                               "EU_Sales": sum, 
                                               "JP_Sales": sum, 
                                               "Global_Sales": sum, 
                                               "Critic_Score": np.mean}) 
by_publisher["Nintendo"]
by_publisher.columns
top_publishers = by_publisher.sort_values("Global_Sales", ascending = False)[0:15][["NA_Sales", "EU_Sales", "JP_Sales"]]
top_publishers
top_publishers.plot(kind="bar", figsize=(12,5))
# And again, as a barplot
top_publishers.plot(kind="bar", stacked = True, figsize=(12,5))
Explanation: Example 2: Video Game Sales
End of explanation
<END_TASK>