We have already experienced an object in Python called DataFrame. DataFrames are not built-in objects: they appeared once we imported data using pandas_datareader. It turns out there is a popular library called pandas which is also responsible for dealing with DataFrames. pandas_datareader is based on pandas, thus, it gets stock data and saves inside a dataframe.
To import pandas library we again (as always) run the following command in Jupyter Notebook (assuming pandas is already installed, which is the case if you used Anaconda):
import pandas
As you know, whenever you want to call a specific function residing inside a library, you need to use its name. This is why we can use the "as" syntax to give a short name to the library as follows:
import pandas as pd
We covered head(), tail() and describ() functions that are available for dataframes, but there are many more to come.
Please note, that the functinos above can be also separately applied to separate columns of the DataFrame.
In [1]:
import pandas as pd
In [3]:
data = pd.read_csv('Training.csv')
In [4]:
data.head()
Out[4]:
In [5]:
data.corr()
Out[5]:
In [6]:
data.cov()
Out[6]:
In [7]:
data.mean()
Out[7]:
In [8]:
data.mode()
Out[8]:
In [9]:
data.median()
Out[9]:
In [10]:
my_corr = data.corr()
In [11]:
my_corr.to_csv("correlation.csv")