I have an excel file and I need to extract certain data from the rows of a certain sheet. So far I have
import pandas as pd
xl_file = pd.ExcelFile((xlfilePath)
dfs = {sheet_name: xl_file.parse(sheet_name) for sheet_name in xl_file.sheet_names}
Now I would like to read the numerical values found in a particular row. The row structure is something like:
Length (mm) 10.1 - 16.0 - 19.5 - 16.4 - 11.3
where I am attempting to show what is in each cell of a row. The dashes indicate an empty entry in a cell! How can I read in a row like this using the pandas library? I happen to know what row number the above row has but would there be a way for pandas to look through the data frame and find the entry length (mm)
instead of having to specify the row number?
Edit: The actual df.loc['length (mm)'] as suggested by EdChum looks like this:
0 17.92377
Unnamed: 1 NaN
0.05 18.55764
Unnamed: 3 NaN
0.1 19.17039
Unnamed: 5 NaN
0.15 19.7507
Unnamed: 7 NaN
0.2 20.29776
Unnamed: 9 NaN
0.25 20.80492
Unnamed: 11 NaN
0.3 21.2667
Unnamed: 13 NaN
0.35 21.67687
Unnamed: 15 NaN
0.4 22.02884
Unnamed: 17 NaN
0.45 22.3156
Unnamed: 19 NaN
0.5 22.53051
Unnamed: 21 NaN
0.55 22.66691
Unnamed: 23 NaN
0.6 22.71949
Unnamed: 25 NaN
0.65 22.68477
Unnamed: 27 NaN
0.7 22.56162
Unnamed: 29 NaN
0.75 22.35258
Unnamed: 31 NaN
0.8 22.06432
Unnamed: 33 NaN
0.85 21.7079
Unnamed: 35 NaN
0.9 21.29801
Unnamed: 37 NaN
0.95 20.85419
Unnamed: 39 NaN
1 20.394
Name: length (mm), dtype: object
Use pandas. read_excel() function to read excel sheet into pandas DataFrame, by default it loads the first sheet from the excel file and parses the first row as a DataFrame column name.
After loading your df you can select a specific row using label indexing loc
:
df.loc['length (mm)']
If you want a np.array from this just do:
df.loc['length (mm)'].values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With