-
Introduction 1
-
Lecture1.1
-
-
Getting the Data 3
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
-
SP500 Webscrape 4
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
-
Full Dataset 2
-
Lecture4.1
-
Lecture4.2
-
-
Regressions 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
-
Machine Learning 5
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
Lecture6.5
-
-
Machine Learning Function 2
-
Lecture7.1
-
Lecture7.2
-
-
Visualize Data 2
-
Lecture8.1
-
Lecture8.2
-
Visualization
import pandas as pd
df = pd.DataFrame.from_csv("GroupedSP500.csv", encoding="UTF-8")
print(df.groupby("Group")["GICS Sector"].value_counts())
Let’s get the mean for our data.
print(df.groupby("Group").mean())
Let’s get rid of CIK column and then also plot a bar graph of all the mean data. We can use plot() to plot a pandas dataframe, and also can use the argument kind to decide what kind of plot.
import matplotlib.pyplot as plt
del df["CIK"]
df.groupby("Group").mean().plot(kind='bar')
plt.show()
Let’s also see about what the bar graph looks like without the index betas.
df[["Gold","NaturalGas","Oil","Group"]].groupby("Group").mean().plot(kind='bar')
plt.show()
Finally, we can get a pie graph as so….
for x in df["GICS Sector"].unique():
frame = df[df["GICS Sector"]==x]
frame["Group"].value_counts().plot(kind='pie',legend=True,title=x)
plt.show()
Source Code
Prev
Introduction