In [253]:
import pandas as pd
In [254]:
!pip install matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [255]:
df = pd.read_csv("07-hw-animals copy.csv")
In [256]:
df.columns.values
Out[256]:
In [257]:
df.head(3)
Out[257]:
In [258]:
df.sort_values(by='length', ascending = False).head(3)
Out[258]:
In [259]:
df['animal'].value_counts()
Out[259]:
In [260]:
df[df['animal'] == 'dog']
Out[260]:
In [261]:
df[df['length']>40]
Out[261]:
In [262]:
df['inches'] = df['length']*0.393701
In [263]:
cats = df[df['animal'] =='cat']
dogs = df[df['animal'] == 'dog']
In [264]:
cats[cats['inches']>12]
Out[264]:
In [265]:
df[(df['animal']=='cat') & (df['inches']>12)]
Out[265]:
In [266]:
cats.describe()
Out[266]:
the mean length of a cat is 14.698 inches
In [267]:
dogs.describe()
Out[267]:
the mean length of a dog is 19.685
In [268]:
df.groupby('animal').mean()
Out[268]:
In [269]:
dogs.hist('length')
Out[269]:
In [270]:
df.plot(kind='bar', x='name', y='length', legend=False)
Out[270]:
In [271]:
df.plot(kind='barh', x='animal', y='length', legend=False)
Out[271]:
In [272]:
sortedcats = cats.sort_values(by='length', ascending = True)
sortedcats.plot(kind='barh', x='animal', y='length', legend=False)
Out[272]:
In [279]:
df = pd.read_excel('billionaires copy.xlsx')
df.columns.values
Out[279]:
In [280]:
recent = df[df['year']==2014]
recent.head(5)
Out[280]:
In [ ]:
In [ ]:
In [282]:
recent.sort_values(by='networthusbillion', ascending=False).head(10)
Out[282]:
In [283]:
recent.groupby('gender').mean()
Out[283]:
In [284]:
recent.sort_values('networthusbillion').head(10)
Out[284]:
In [295]:
rel_counts = recent.groupby('relationshiptocompany').count()
rel_counts.sort_values('year', ascending=False).head(10)
#relationship to company describes the role a person plays in a company
#most common relationshops are founder, relation, owner, chairman, and investor
Out[295]:
In [298]:
source_counts = recent.groupby('sourceofwealth')
Out[298]:
In [ ]:
In [ ]: