I have an excel file in the following format:
I want to read it using Python and concatenate the tables(the number of tables could change) into a single one, and add a column with the road name next to each table
So it would look like:
I read in the excel file
import pandas as pd df = pd.read_excel(input_fp, dtype='str').dropna(how='all')
And the dataframe looks like:
I'm thinking that splitting the dataframe by columns with all nan values, or columns with a header should work. But unsure how to do this.
Any suggestions would be appreciated
Test data:
{'Unnamed: 0': {0: 'Start Time', 1: '06:01:00', 2: '06:31:00', 3: '07:31:00', 4: '08:31:00'}, 'Unnamed: 1': {0: 'End Time', 1: '06:30:00', 2: '07:30:00', 3: '08:30:00', 4: '09:30:00'}, 'Unnamed: 2': {0: 'Number of Cars', 1: '5343', 2: '2545', 3: '2434', 4: '3424'}, 'Unnamed: 3': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan}, 'Unnamed: 4': {0: 'Start Time', 1: '06:01:00', 2: '06:31:00', 3: '07:31:00', 4: '08:31:00'}, 'Unnamed: 5': {0: 'End Time', 1: '06:30:00', 2: '07:30:00', 3: '08:30:00', 4: '09:30:00'}, 'Unnamed: 6': {0: 'Number of Cars', 1: '5343', 2: '2545', 3: '2434', 4: '3424'}, 'Unnamed: 7': {0: nan, 1: nan, 2: nan, 3: nan, 4: nan}, 'Unnamed: 8': {0: 'Start Time', 1: '06:01:00', 2: '06:31:00', 3: '07:31:00', 4: '08:31:00'}, 'Unnamed: 9': {0: 'End Time', 1: '06:30:00', 2: '07:30:00', 3: '08:30:00', 4: '09:30:00'}, 'Unnamed: 10': {0: 'Number of Cars', 1: '5343', 2: '2545', 3: '2434', 4: '3424'}}



df.head().to_dict()by text.df = pd.read_excel(input_fp, header=1, dtype='str').dropna(how='all')Then, if you providedf.head().to_dict()by text, we will tell you how to reshape.df = pd.read_excel(input_fp, header=1, dtype='str').dropna(how='all')header=1 is important. plz make header & providedf.head().to_dict()