-
Notifications
You must be signed in to change notification settings - Fork 1
/
xlsx_examples.py
61 lines (41 loc) · 1.61 KB
/
xlsx_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def read_workbook_sheet_titles_with_pandas():
import pandas as pd
xl_io = pd.ExcelFile("DataStores/all_data.xlsx")
print(xl_io.sheet_names)
def read_worksheets_with_pandas():
import pandas as pd
xl_io = pd.ExcelFile("DataStores/all_data.xlsx")
tickers = xl_io.sheet_names
lows = pd.DataFrame(columns=[t + "_low" for t in tickers])
for t in tickers:
lows[t + "_low"] = pd.read_excel(xl_io, sheet_name=t, index_col=0, parse_dates=True)["low"]
print(lows.head())
print(lows.describe())
def plot_with_matplotlib():
import pandas as pd
from matplotlib import pyplot as plt
xl_io = pd.ExcelFile("DataStores/all_data.xlsx")
tickers = xl_io.sheet_names
lows = pd.DataFrame(columns=[t + "_low" for t in tickers])
for t in tickers:
lows[t + "_low"] = pd.read_excel(xl_io, sheet_name=t, index_col=0, parse_dates=True)["low"]
((lows-lows.mean())/lows.std()).plot(figsize=(15,7))
plt.show()
def read_xlsx_with_headers():
import pandas as pd
h = pd.read_excel("DataStores/all_data_header.xlsx",
sheet_name='AAPL', index_col=0, parse_dates=True).head()
print(h)
print("""
-------------------------------------------
""")
skip3_h = pd.read_excel("DataStores/all_data_header.xlsx",
sheet_name = 'AAPL',
index_col=0, parse_dates=True, skiprows=3).head()
print(skip3_h)
if __name__ == "__main__":
# read_workbook_sheet_titles_with_pandas()
# read_worksheets_with_pandas()
# plot_with_matplotlib()
# read_xlsx_with_headers()
pass