My excel data looks like this:
A B C
1 RAM 53.44 576
2 MOHAN 74.34 345
3 KISHAN 76.65 285
How can I extract headers contents from spreadsheets?
My excel data looks like this:
A B C
1 RAM 53.44 576
2 MOHAN 74.34 345
3 KISHAN 76.65 285
How can I extract headers contents from spreadsheets?
Your question is really unclear. However you can use pandas library to read file excel format.
import pandas as pd
print(pd.read_excel('file.xlsx').columns)
Call to .columns
list the headers of all the columns
Output example:
Index(['id', 'email','server','profession'], dtype='object')
EDIT:
Ok now I see you have very odd first to rows which do not comply with pandas data structure. The simplest solution is to skip the first two rows. And then import it into panadas DataFrame
use skiprows
to skip first n rows. In your case 2
import pandas as pd
print(pd.read_excel('file.xlsx',skiprows=2).columns)
Check out Pandas. It's a lot better than Xlrd and uses less code.
You should be able to get it's index, regardless of whether or not it's a header.
From memory think you have to use df.head()
once you've created your dataframe.
#static code if header at 0,0 position
import xlrd
loc = ("path of file")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
# For row 0 and column 0
sheet.cell_value(0, 0)
for i in range(sheet.ncols):
print(sheet.cell_value(0, i))