Код: Выделить всё
# save xlsx to variable
xls = pd.ExcelFile("Test1.xlsx")
# create a new csv to write everything to
with open('emails.csv', 'w') as creating_new_csv_file:
pass
# for each sheet in the file, get the 3 necessary columns saved to a variable
for sheet_name in xls.sheet_names:
read_file = pd.read_excel('Test1.xlsx', sheet_name=[f'{sheet_name}'], header=0, usecols=['Page', 'URL', 'Person'])
# now loop through that dictionary object to exclude the actual sheet name and be able to output to csv
for sheet in read_file:
print(read_file[sheet])
# adds the data to the CSV created earlier. However, only adds the final sheet, whereas
# I want to be appending each one so that they are all in the CSV together.
read_file[sheet].to_csv("emails.csv",
index=False,
header=True,
columns=['Page', 'URL', 'Person']
)
Пожалуйста, дайте мне знать, если мой запрос не имеет смысла!
Подробнее здесь: https://stackoverflow.com/questions/772 ... a-csv-file