<jupyter_start><jupyter_text>Pandas-1Saket TiwariDate: 06 June 2019<jupyter_code>#pandas are used when we have strings
#we cannot use strings in numpy
import pandas as pd
! pip install pandas
import pandas as pd
df=pd.read_csv('data/data/gapminder.tsv',sep='\t')
#in pandas 1-D :Series 2-D: DataFrame
df.head(3)
df.tail(5)
type(df)
df.shape
#shape is an attribute describing properties
df.info()
df.describe()
df.columns
#it is also a property
df.columns=['country', 'continent', 'year', 'lifeExp', 'population', 'gdpPercap']
df.head()
df.keys()
df['country'].head()
df[['country','continent']].head()
df.drop('population',axis=1,inplace=True)
#axis telss that delete the value from every row
df.head()
df=pd.read_csv('data/data/gapminder.tsv',sep='\t')
df
#iloc is used when working with index
#loc is used when working with label
df.loc[10]
df.loc[[10,100]]
df.iloc[-1] #because -1 represents the ;last index
#df.loc[-1]#gives error because no label with -1
df.loc[2:7]
#7 is included
df.iloc[2:7] #7not included
df.iloc[3:7,1:4]
df.loc[3:7,['country','year']]
#since labels are strings therefore we cannot use 1:4 here
df.loc[3:7,:]
df.iloc[[1,10,100],[0,2,3]]
m=df['lifeExp'].mean()
#df['lifeExp'] is a series and all the operations in numpy
#it is not a right way to calculate mean for categorical data
#we use weighted mean ther
a=df['lifeExp']>59
a.head()
df.loc[df.lifeExp>59].head()
df.loc[df.lifeExp>m].head()
df.loc[df.lifeExp>59, ['lifeExp','country']].head()
df.loc[(df.lifeExp>51) & (df.lifeExp<53)]
df.loc[(df.lifeExp<29) | (df.lifeExp>65)].head()
df.loc[df.country=='India']
df.loc[df.country<'India']
df.loc[df.country>'India']
df.groupby('year')['lifeExp','gdpPercap'].mean().reset_index().head()
df.groupby(['year','continent'])['lifeExp','gdpPercap'].mean()
df.groupby(['continent','year'])['lifeExp','gdpPercap'].mean().reset_index()
df.groupby('continent')['country'].nunique()
df.sort_values(['year','lifeExp'],ascending=[1,0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.198989898989899, 'fraction_numerical': 0.03232323232323232, 'mean_word_length': 6.861111111111111, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '544584', 'license': 'MIT', 'n_tokens_mistral': 803, 'n_tokens_neox': 763, 'n_words': 175, 'path': 'Basics/Pandas-1.ipynb', 'repo_name': 'saket-iiitR/Machine-Learning-Works', 'size': '1980'}