1import pandas as pd
2
3def read_excel_sheets(xls_path):
4 """Read all sheets of an Excel workbook and return a single DataFrame"""
5 print(f'Loading {xls_path} into pandas')
6 xl = pd.ExcelFile(xls_path)
7 df = pd.DataFrame()
8 columns = None
9 for idx, name in enumerate(xl.sheet_names):
10 print(f'Reading sheet #{idx}: {name}')
11 sheet = xl.parse(name)
12 if idx == 0:
13 # Save column names from the first sheet to match for append
14 columns = sheet.columns
15 sheet.columns = columns
16 # Assume index of existing data frame when appended
17 df = df.append(sheet, ignore_index=True)
18 return df
19
1xls = pd.ExcelFile('path_to_file.xls')
2df1 = pd.read_excel(xls, 'Sheet1')
3df2 = pd.read_excel(xls, 'Sheet2')
1import pandas as pd
2
3df = pd.read_excel(excel_file_path, sheetname="sheet_name")
4
1stops2 = read_excel_sheets("data/PIANorthCarolina_02152019.xlsx")
2stops2.to_csv("data/stops.01end.csv", mode="a", header=False, index=False)
3