Python - Pandas - Extract EXERE excel file as a string

I would like to read many excel files using pandas (python). When importing data, I want ALL of my columns to be saved as rows.

The problem is that I don’t know the number of columns or even their names (this changes every time). Will you have a simple solution to this problem?

What I tried to do:

converters = { i : str for i in range(0,99)}
df = pd.read_excel('example.xlsx', converters = converters)

But the index is sometimes out of range because excel files are different.

Ideally, I would like to do:

df = pd.read_excel('example.xlsx', converters = ALL)

However, I have not found anything that would help me do something like this so far ...

Thank you for your help.

+4
source share
1 answer

UPDATE: , ( Pandas) xlrd , Excel

xl = pd.ExcelFile(fn)
ncols = xl.book.sheet_by_index(0).ncols
df = xl.parse(0, converters={i : str for i in range(ncols)})

OLD answer:

, :

from openpyxl import load_workbook

workbook = load_workbook(filename, use_iterators=True)
col_num = workbook.worksheets[0].max_column

converters = { i : str for i in range(col_num)}
...
+4

Source: https://habr.com/ru/post/1666624/


All Articles