簡體   English   中英

如何在python中對Excel文件的輸出的列求和?

[英]How to sum over the columns of the output of an excel file in python?

我正在嘗試對從excel文件中獲得的矩陣的所有列求和,但問題是python忽略了第一列,僅計算3x3矩陣的第二和第三列的總和。

這是print(data)的輸出:

data = pd.read_excel("data.xlsx", header = None)
print(data.sum(axis=0))

這是里面的data

      0     1   2
0  NaN   17.0   5
1     3   NaN  19
2     7  17.0   7

那么,我應該怎么做才能對所有三列求和?

如果您所有的列都應該是浮點數,則可以在執行導入時聲明:

# where the range is the number of columns you have
dtypes = {col: float for col in range(3)}
data = pd.read_excel("data.xlsx", header = None, dtype = dtypes)
print(data.sum())

出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM