@@ -29,7 +29,6 @@ Print the first 10 Rows from a Dateframe. (Method .head(amount))
29
29
print(df.head(10))
30
30
```
31
31
32
-
33
32
## Print Rows from a Dateframe and sort them with an attribute 🗃
34
33
Print 10 Rows from a Dateframe using an Integer Index from 0-10 and sort them with an attribute. (Method .sort_values([ "Start Time"] ))
35
34
```
@@ -54,3 +53,40 @@ data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada', 'Nevada'],
54
53
# Create Data Frame
55
54
df = pd.DataFrame(data)
56
55
```
56
+
57
+ ## Draw financial Chart 🗂
58
+ ```
59
+ import pandas as pd
60
+ import matplotlib.pyplot as plt
61
+ import matplotlib
62
+ from datetime import datetime
63
+
64
+ fig = plt.figure()
65
+ ax = fig.add_subplot(1, 1, 1)
66
+
67
+ data = pd.read_csv('spx.csv', index_col=0, parse_dates=True)
68
+ spx = data['SPX']
69
+
70
+ spx.plot(ax=ax, style='k-')
71
+
72
+ crisis_data = [
73
+ (datetime(2007, 10, 11), 'Peak of bull market'),
74
+ (datetime(2008, 3, 12), 'Bear Stearns Fails'),
75
+ (datetime(2008, 9, 15), 'Lehman Bankruptcy')
76
+ ]
77
+
78
+ for date, label in crisis_data:
79
+ ax.annotate(label, xy=(date, spx.asof(date) + 75),
80
+ xytext=(date, spx.asof(date) + 225),
81
+ arrowprops=dict(facecolor='black', headwidth=4, width=2,
82
+ headlength=4),
83
+ horizontalalignment='left', verticalalignment='top')
84
+
85
+ # Zoom in on 2007-2010
86
+ ax.set_xlim(['1/1/2007', '1/1/2011'])
87
+ ax.set_ylim([600, 1800])
88
+
89
+ ax.set_title('Important dates in the 2008-2009 financial crisis')
90
+
91
+ fig.show()
92
+ ```
0 commit comments