Empty columns of a spreadsheet when using pandas read()

Asked

Viewed 181 times

0

import pandas as pd

wb = pd.ExcelFile("meus_dados.xlsx")

sheet_1 = pd.read_excel("meus_dados.xlsx", sheet_name=0)

print sheet_1

that line of code brings me that answer:

             Nome          CPF     ...      Unnamed: 8  Unnamed: 9
0     Silvio José  10575674451     ...             NaN         NaN
1  Carlos Alberto  10767764330     ...             NaN         NaN
2  Maria Madalena  23323234343     ...             NaN         NaN
3    Caio Bezerra  10992329221     ...             NaN            
4  Mateus Alencar  10732393213     ...             NaN         NaN

[5 rows x 10 columns]

I don’t know why these empty columns appear in 8 and 9. When I read another sheet empty columns do not appear.

  • And what’s the spreadsheet?

  • 1

    Regardless, you shouldn’t be working with Python 2-version 2.7 was released 10 years ago (micro-versions are just security fixes) - and all support will be discontinued as of January 1, 2020.

1 answer

0


On the spreadsheet - it logically contains some data in these columns - they can be simple blank characters in some cell (column 9, on row 3 seems to be an indiciative of one of these). Simply select columns 8 and 9 in excel and remove its contents, then save the file again.

If you have this happening in many worksheets and prefer to automate this filter, then it is worth passing an "apply" and removing columns that only have "Nan" values or strings with white-space. But for a single spreadsheet, it is best to clean the original.

  • Deleting cell data did not work, but I created a new spreadsheet and it worked. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.