long time user of stackoverflow, first time poster, so all help is appreciated :)
TLDR; Is there a parameter for read_excel that I am missing to keep all columns (i.e. not remove any, even if they are blank)?
Issue in detail: When using read_excel, I have a blank column as the first column in one of the sheets I am reading in. This blank column is then removed from the dataframe, which in turn messes up the rest of the code as it relies on the column index's being the same between the sheets. I cannot code around it due to the rest of the sheets following this standardized format. The code following this is correct. When adding a filler value into the blank column, the code works. This is not a solution due to logic needed for blank values in column index 0 (column A) being set to a certain value.
Pandas.read_excel documentation
import pandas as pd
df = pd.read_excel(
"test.xlsx,
sheet_name = "MYSHEET",
# Missing parameter that i cannot figure out
)
# Code following this is looping row by row, column by column of each item in dataframe to get desired output
Input excel file has double headers, and columns A, B, C are getting pivoted into header values (hence I need to keep blank columns)
CodePudding user response:
Seems like you can use usecols
:
df = pd.read_excel(
"test.xlsx",
sheet_name="MYSHEET",
usecols="A:MV"
)
CodePudding user response:
This should fix the issue.
df = pd.read_excel(
"test.xlsx,
sheet_name = "MYSHEET",
skip_blank_lines=False
)