The read_excel function used when reading data from Excel as a DataFrame, As mentioned in the reference, even if you specify the sheet name with sheet_name, no error occurs, but sometimes the sheet could not be acquired correctly. (No matter how I specified it, I could only get the first sheet)
import pandas as pd #version 0.20.0
df = pd.read_excel(input_path, sheet_name="Sheet2") #I want to load the second sheet
print(df) #For some reason the contents of the first sheet come out
Apparently, sheet_name doesn't work in the environment of ** pandas 0.20 or earlier ** and it is correct to specify it by sheetname (why sheet_name can also be used as a keyword ...) By the way, in pandas 0.23, when I use sheetname, a warning is displayed, but both sheetname and sheet_name work. In the latest version, the sheetname keyword has already been deleted and only the sheet_name keyword can be used.
df = pd.read_excel(input_path, sheetname="Sheet2") #Sheetname without hyphens
print(df) #I got the second sheet properly
Recommended Posts