![](/img/trans.png)
[英]how to check whether the id in df1 existed in df2 when date in df2 is older than date in df1 and add new column accordingly using pandas
[英]How to add text at the end of df in pandas when export df to Excel
我在 pandas 中有幾個 df ,我將它們導出到 excel ,如下所示:
with pd.ExcelWriter('result.xlsx') as writer:
df_1.to_excel(writer, sheet_name='one')
df_2.to_excel(writer, sheet_name='two')
我想在 df 的末尾在同一張表“one”中添加一些文本,例如text1 = 'Done'
這個不起作用:
with pd.ExcelWriter('result.xlsx') as writer:
df_1.to_excel(writer, sheet_name='one')
df_2.to_excel(writer, sheet_name='two')
text1.to_excel(writer, startrow=20, sheet_name='one')
而且我無法弄清楚正確的語法。 你能幫幫我嗎? PS 我可以提前計算正確的startrow
以不覆蓋 df 數據。 謝謝!
您可以在df
的末尾添加一行,並將 Done 添加到其中一列,方法是使其他列為零。 例如,假設您有四列
new_row = {'col1': '', 'col2': 'Done', 'col3': '', 'col4': ''}
df = df.append(new_row, ignore_index=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.