In [3]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
s = pd.Series(data, index=index)
data
can beindex
is a list that will become item lables (like the keys in a dictionary
In [6]:
# make a list of random numbers
a_python_list = list(np.random.randn(5))
a_python_list
Out[6]:
In [8]:
a_pandas_series = pd.Series(data=a_python_list)
a_pandas_series
Out[8]:
dype
associated with the items in the list
In [9]:
a_simple_index = ['a', 'b', 'c', 'd', 'e']
a_pandas_series = pd.Series(data=a_python_list, index=a_simple_index)
a_pandas_series
Out[9]:
In [10]:
# index by label
a_pandas_series['a']
Out[10]:
In [11]:
# index by location
a_pandas_series[1]
Out[11]:
In [12]:
a_python_dictionary = {'a' : 0., 'b' : 1., 'c' : 2.}
pd.Series(a_python_dictionary)
Out[12]:
In [14]:
a_big_series = pd.Series(np.random.randn(1000))
a_big_series
Out[14]:
In [15]:
a_big_series * 2
Out[15]:
In [18]:
a_big_series.sum() / len(a_big_series)
Out[18]:
In [16]:
a_big_series.mean()
Out[16]:
In [17]:
a_big_series.describe()
Out[17]:
In [26]:
a_dictionary = {'one' : [1., 2., 3., 4.],
'two' : [4., 3., 2., 1.]}
a_dataframe = pd.DataFrame(a_dictionary)
a_dataframe
Out[26]:
In [27]:
a_dataframe = pd.DataFrame(a_dictionary,
index=['a', 'b', 'c', 'd'])
a_dataframe
Out[27]:
In [29]:
a_list_of_dictionaries = [{'a': 1, 'b': 2}, {'a': 5, 'b': 10, 'c': 20}]
a_dataframe = pd.DataFrame(a_list_of_dictionaries)
a_dataframe
Out[29]:
In [30]:
a_dataframe['a']
Out[30]:
In [33]:
a_dataframe = pd.DataFrame({'a': np.random.randn(1000),
'b': np.random.randn(1000),
'c': np.random.randn(1000),
'd': np.random.randn(1000),
'e': 'hi'})
a_dataframe
Out[33]:
In [34]:
a_dataframe.dtypes
Out[34]:
In [35]:
a_dataframe.describe()
Out[35]:
In [36]:
a_dataframe.to_csv("random-data.csv")
In [38]:
a_dataframe.to_excel("random-data.xls")
In [39]:
a_dataframe.to_excel("random-data.xls", index=False)
a_dataframe.to_csv("random-data.csv", index=False)
In [41]:
a_new_dataframe = pd.read_csv("random-data.csv")
a_new_dataframe
Out[41]:
In [42]:
a_new_dataframe.dtypes
Out[42]:
In [43]:
a_new_dataframe.plot()
Out[43]:
In [45]:
a_new_dataframe['a'].plot()
Out[45]:
plot()
functiondataframe.plot()
has a lot of good information
In [47]:
a_new_dataframe.plot(kind="box")
Out[47]:
In [49]:
a_new_dataframe.plot(kind="density")
Out[49]:
In [44]:
a_new_dataframe.hist()
Out[44]:
In [ ]: