import an excel sheet as dataframe, all values will be string in python

To import an excel sheet as a pandas DataFrame in python, with all values as string, you can use the read_excel function of the pandas library.

main.py
import pandas as pd

# read excel sheet and convert all values to string
df = pd.read_excel('path/to/excel_file.xlsx', dtype=str)
130 chars
5 lines

The read_excel function reads the excel sheet at the specified filepath and returns a DataFrame object. The dtype=str parameter tells pandas to convert all values to string. If you don't specify this parameter, pandas will try to infer the datatype of each column, which may not always give you the desired outcome.

gistlibby LogSnag