Код: Выделить всё
x1 = np.random.randn(100, 2)
df1 = pd.DataFrame(x1)
with pd.ExcelWriter('/tmp/sample.xlsx') as writer:
df1.to_excel(writer, sheet_name='x1')
< /code>
/tmp/sample.xlsxТеперь мы можем добавить еще один DataFrame в comemp/sample.xlsx с существующим файлом x1 .
Код: Выделить всё
x2 = np.random.randn(100, 2)
df2 = pd.DataFrame(x2)
with pd.ExcelWriter('/tmp/sample.xlsx', engine='xlsxwriter',mode='a') as writer:
df2.to_excel(writer, sheet_name='x2')
< /code>
engineЗаменить xlsx на ODS , мы не можем записать DataFrame в Excel OpenOffice-OD с существующим файлом. Br />
Код: Выделить всё
x1 = np.random.randn(100, 2)
df1 = pd.DataFrame(x1)
with pd.ExcelWriter('/tmp/sample.ods') as writer:
df1.to_excel(writer, sheet_name='x1')
< /code>
Now add a new sheet in the '/tmp/sample.ods'.
x2 = np.random.randn(100, 2)
df2 = pd.DataFrame(x2)
with pd.ExcelWriter('/tmp/sample.ods', engine='xlsxwriter',mode='a') as writer:
df2.to_excel(writer, sheet_name='x2')
< /code>
It encounter error:
ValueError: Append mode is not supported with xlsxwriter!
< /code>
Try another engine odfКод: Выделить всё
x2 = np.random.randn(100, 2)
df2 = pd.DataFrame(x2)
with pd.ExcelWriter('/tmp/sample.ods', engine='odf',mode='a') as writer:
df2.to_excel(writer, sheet_name='x2')
< /code>
Same error:
ValueError: Append mode is not supported with odf!
< /code>
Without the mode='a'Подробнее здесь: https://stackoverflow.com/questions/793 ... sting-file