In [3]:
import pandas as pd
In [4]:
!pip install matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [ ]:
df = pd.read_csv("07-hw-animals copy.csv")
In [ ]:
df.columns.values
In [ ]:
df.head(3)
In [ ]:
df.sort_values(by='length', ascending = False).head(3)
In [ ]:
df['animal'].value_counts()
In [ ]:
df[df['animal'] == 'dog']
In [ ]:
df[df['length']>40]
In [ ]:
df['inches'] = df['length']*0.393701
In [ ]:
cats = df[df['animal'] =='cat']
dogs = df[df['animal'] == 'dog']
In [ ]:
cats[cats['inches']>12]
In [ ]:
df[(df['animal']=='cat') & (df['inches']>12)]
In [ ]:
cats.describe()
the mean length of a cat is 14.698 inches
In [ ]:
dogs.describe()
the mean length of a dog is 19.685
In [ ]:
df.groupby('animal').mean()
In [ ]:
dogs.hist('length')
In [ ]:
df.plot(kind='bar', x='name', y='length', legend=False)
In [ ]:
df.plot(kind='barh', x='animal', y='length', legend=False)
In [ ]:
sortedcats = cats.sort_values(by='length', ascending = True)
sortedcats.plot(kind='barh', x='animal', y='length', legend=False)
In [6]:
df = pd.read_excel('billionaires copy.xlsx')
df.columns.values
Out[6]:
In [7]:
recent = df[df['year']==2014]
recent.head(5)
Out[7]:
In [9]:
recent['countrycode'].value_counts()
Out[9]:
In [ ]:
In [10]:
recent.sort_values(by='networthusbillion', ascending=False).head(10)
Out[10]:
In [11]:
recent.groupby('gender')['networthusbillion'].mean()
Out[11]:
In [12]:
recent.sort_values('networthusbillion').head(10)
Out[12]:
In [18]:
recent.groupby('relationshiptocompany')['relationshiptocompany'].count()
Out[18]:
In [31]:
recent.groupby('gender')['sourceofwealth'].sort_values()
In [ ]:
In [24]:
recent['industry'].value_counts()
Out[24]:
In [29]:
recent.groupby('industry')['networthusbillion'].sum().sort_values(ascending=False).head(10)
Out[29]:
In [ ]: