In [6]:
import pandas as pd
In [7]:
df = pd.read_csv("07-hw-animals.csv")
In [8]:
!pip install matplotlib
In [9]:
%matplotlib inline
In [10]:
df
Out[10]:
In [11]:
df.columns
Out[11]:
In [12]:
df.columns.values
Out[12]:
In [13]:
df[['name']].head(3)
Out[13]:
In [14]:
df.sort_values('length', ascending=False).head(3)
Out[14]:
In [15]:
df['animal'].value_counts()
Out[15]:
In [16]:
df[df['animal'] == 'dog']
Out[16]:
In [17]:
df[df['length'] > 40]
Out[17]:
In [18]:
df['inches'] = df['length'] * 0.39
df.head()
Out[18]:
In [19]:
cats = df['animal'] == 'cat'
#print(cats)
dogs = df['animal'] == 'dog'
#print(dogs)
In [20]:
cats_above_12_inches = df['inches'] >12
cats = df['animal'] == 'cat'
df[cats & cats_above_12_inches]
Out[20]:
In [21]:
df[(df['animal'] == 'cat') & (df['inches'] > 12)]
Out[21]:
In [22]:
#df['length'].describe()
cats= df[df['animal'] == 'cat']
cats["length"].describe()
Out[22]:
In [23]:
dogs= df[df['animal'] == 'dog']
dogs["length"].describe()
Out[23]:
In [24]:
df.groupby('animal')['length'].describe()
Out[24]:
In [31]:
dogs["length"].hist()
Out[31]:
In [38]:
dogs["length"].plot(kind='pie', y=dogs['length'],labels=dogs['name'], legend=False)
Out[38]:
In [46]:
df.plot(kind='barh', x='name', y='length', legend=False)
Out[46]:
In [56]:
cats_ordered= cats.sort_values(by='length', ascending=True)
print(cats_ordered)
cats_ordered.plot(kind='barh', x='name', y='length', legend=False)
Out[56]:
In [ ]: