I want to loop through multiple Excel sheets to extract cell values (in this example, it'd be A1, B2, A3), and display values from each sheet in a row (see examples below). The source file is a bit messy, with row labels ('Fruit name', 'object type', 'count') that has been removed for simplification.
I was able to extract cell values from a single column (see current code), but need helping getting values scattered throughout two columns. In my real-life project, I have many more cells, so it is important that the solution is scalable. I tried Openpyxl last week, but have reverted to pandas as pd seems to be more versatile. Ideas on how to write clean code for this would be much appreciated!
Sheet Format
A B
0 Apples
1 Fruit
2 5
Desired output
Values from multiple sheets displayed as rows in a new sheet:
A B C
Apples Fruit 5
Cilanto Herb 4
Current code
result=[]
for i in File.sheet_names:
df = pd.read_excel(File.xlsx', sheet_name=i)
cells = df.iloc[[0, 2], [1]]
result.append(cells)
result = pd.concat(result, axis=1).T