Ваш вопрос не имеет ничего общего с Spark или PySpark.Это связано с Pandas .
Это потому, что Pandas автоматически интерпретирует и выводит тип данных столбцов.Поскольку все значения вашего столбца являются числовыми, Pandas будет рассматривать его как float
тип данных.
Чтобы избежать этого, метод pandas.ExcelFile.parse
принимает аргумент с именем converters
, поэтому выможет использовать это, чтобы сообщить Pandas конкретный тип данных столбца:
# if you want one specific column as string
df = pd.concat([filepath_pd.parse(name, converters={'column_name': str}) for name in names])
ИЛИ
# if you want all columns as string
# and you have multi sheets and they do not have same columns
# this merge all sheets into one dataframe
def get_converters(excel_file, sheet_name, dt_cols):
cols = excel_file.parse(sheet_name).columns
converters = {col: str for col in cols if col not in dt_cols}
for col in dt_cols:
converters[col] = pd.to_datetime
return converters
df = pd.concat([filepath_pd.parse(name, converters=get_converters(filepath_pd, name, ['date_column'])) for name in names]).reset_index(drop=True)
ИЛИ
# if you want all columns as string
# and all your sheets have same columns
cols = filepath_pd.parse().columns
dt_cols = ['date_column']
converters = {col: str for col in cols if col not in dt_cols}
for col in dt_cols:
converters[col] = pd.to_datetime
df = pd.concat([filepath_pd.parse(name, converters=converters) for name in names]).reset_index(drop=True)