Home > Enterprise >  Pandas doesn't read the xlsx fully. What could be the reason?
Pandas doesn't read the xlsx fully. What could be the reason?

Time:12-22

Pandas does read only the last two columns from the xlsx file, replacing the rest of the data with NaN. I tried to create new files, tried it on different sheets with different data but it doesn't change.

I need to create a list and some dictionaries from this table. However, Pandas read only the last two columns, and I don't understand what could be the problem. The Excel Table

Books_ToRead = pd.read_excel("ORO_Project.xlsx", sheet_name="Books")

Then, when I tried to create a list with it, I got a KeyError: 'Book Name'.

book_list = Books_ToRead["Book Name"].tolist()

I printed the excel file to see what the problem can be, and it seems that it replaces all the data from the first columns with NaN.

What could be the problem and how can I fix it?

CodePudding user response:

Look at your Excel file: there are 3 empty rows at the top and 2 empty columns on the left. Simply remove them.

The reason you're only seeing the last two columns when you look at the df is because the other ones (which do in fact have data) have been hidden following pd.options.display.max_columns.

  • Related