[英]Pandas creates new excel sheet when trying to append to existing sheet
[英]Trying to append the sum of an existing dataframe into a new excel sheet
So I have been trying to append the df.sum()
of an existing dataframe into a new dataframe for a new excel.Consider
the below example:
A B C
10 10 10
10 10 10
10 10 10
我希望將其附加到新的 excel 為:
A B C
30 30 30
以下是我在特定位置合並文件的代碼
all_data = pd.DataFrame()
for f in glob.glob("D:\\data_integration\\*.csv"):
print(f)
df = pd.read_csv(f ,encoding='iso-8859-1')
all_data = all_data.append(df,ignore_index=True)
print(all_data)
##appended_df = pd.concat(all_data)
y = all_data.to_csv("D:\\merged2.csv",index=False)
我需要求和部分的幫助。
嘗試
import pandas as pd
df = pd.DataFrame({
'A':[10,10,10],
'B':[10,10,10],
'C':[10,10,10]
})
df.sum().to_frame().T
結果:
A B C
0 30 30 30
當你這樣做時:
df.sum()
A 30
B 30
C 30
dtype: int64
那么你想制作系列到 df
df.sum().to_frame()
0
A 30
B 30
C 30
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.