[英]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.