The issue is with sheet_name = i
. The sheet_name
argument is expecting a string, but you're passing it the whole dataframe that you're trying to output to Excel.
The easiest way to resolve would probably to omit the argument and use the defaults (Sheet1
, Sheet2
, etc.). Alternatively, you could use enumerate
to easily number the dataframes and split them into several excel files like so:
df_split = np.array_split(promotion1, 4)
for index, i in enumerate(df_split):
filename = "result_promotion" + str(index) + ".xlsx"
i.to_excel(filename, index = False)
Alternatively, this post (How to save a new sheet in an existing excel file, using Pandas?) goes into how to add a new sheet to an existing Excel file using pd.ExcelWriter
.
Just to explain the error: since sheet_name
expects a string and you're giving it a different object, pandas will attempt to hash the object to get a unique string representation of it instead. However, since DataFrames are mutable - you can change values in it, unlike a tuple - they cannot be hashed. See this post for a more detailed explanation on why hashable objects must be immutable.