<jupyter_start><jupyter_text>pivot table<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
print(sns.get_dataset_names())
flights_data=sns.load_dataset('flights')
flights_data_pivot=flights_data.pivot_table(index='month',columns='year'
                                            ,values='passengers') 
flights_data_pivot.head()
flights_data_pivot.loc[('May',1960)]
from matplotlib import pyplot as plt
flights_data_pivot.loc[('Jan',1950)]
flights_data.head()<jupyter_output><empty_output><jupyter_text>cross tabulationThe	crosstab()	function	is	used	to	plot	cross	tabulation	between	two	columns.	Let’splot	a	cross	tab	matrix between	passenger	class	and	age	columns	for	the	Titanic	dataset.<jupyter_code>titanic=sns.load_dataset('titanic')
titanic.head()
pd.crosstab(titanic['survived'],titanic['pclass'],margins=True)
a=titanic[(titanic['sex']=='female') & (titanic['survived']==1)]
a['sex'].value_counts()<jupyter_output><empty_output><jupyter_text>Arithmetic	Operations	with	WhereThe	where	clause	from	the	numpy	library	can	be	used	to	perform	arithmetic	operations	on	Pandas	dataframe.	For instance,	in	the	following	script,	the	where	clause	is	used	to	add	5	to	the	rows	in	the	Fare	column,	where passengers’	ages	are	greater	than	20.<jupyter_code>np.where(titanic['age']>20,titanic['fare']-10,titanic['fare'])
titanic.fare.apply(lambda x:x-10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11563169164882227, 'fraction_numerical': 0.01284796573875803, 'mean_word_length': 7.057471264367816, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '220952', 'license': 'MIT', 'n_tokens_mistral': 559, 'n_tokens_neox': 541, 'n_words': 108, 'path': 'AI pandas/pandas3.ipynb', 'repo_name': 'datascientist681/projects', 'size': '1401'}