久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Python Dataframe 中對行求和

Summing rows in Python Dataframe(在 Python Dataframe 中對行求和)
本文介紹了在 Python Dataframe 中對行求和的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我剛開始學習 Python,如果這個問題已經(jīng)在其他地方得到回答,請原諒我.我想創(chuàng)建一個名為Sum"的新列,它只是之前添加的列.

I just started learning Python so forgive me if this question has already been answered somewhere else. I want to create a new column called "Sum", which will simply be the previous columns added up.

Risk_Parity.tail()

    VCIT  VCLT  PCY     RWR     IJR     XLU     EWL
Date                            
2017-01-31  21.704155   11.733716   9.588649    8.278629    5.061788    7.010918    7.951747
2017-02-28  19.839319   10.748690   9.582891    7.548530    5.066478    7.453951    7.950232
2017-03-31  19.986782   10.754507   9.593623    7.370828    5.024079    7.402774    7.654366
2017-04-30  18.897307   11.102380   10.021139   9.666693    5.901137    7.398604    11.284331
2017-05-31  63.962659   23.670240   46.018698   9.917160    15.234977   12.344524   20.405587

表格列有點偏,但我只需要 (21.70 + 11.73...+7.95)我只能創(chuàng)建列 Risk_Parity['sum'] = ,但后來我迷路了.

The table columns are a little off but all I need is (21.70 + 11.73...+7.95) I can only get as far as creating the column Risk_Parity['sum'] = , but then I'm lost.

我寧愿不必這樣做 Risk_Parity['sum] = Risk_Parity['VCIT'] + Risk_Parity['VCLT']...

創(chuàng)建總和列后,我想將每一列除以總和列,并將其制成一個新的數(shù)據(jù)框,其中不包括總和列.

After creating the sum column, I want to divide each column by the sum column and make that into a new dataframe, which wouldn't include the sum column.

如果有人能提供幫助,我將不勝感激.請盡量降低你的答案,哈哈.

If anyone could help, I'd greatly appreciate it. Please try to dumb your answers down as much as possible lol.

謝謝!

湯姆

推薦答案

使用 sum 和參數(shù) axis=1 指定行的總和

Use sum with the parameter axis=1 to specify summation over rows

Risk_Parity['Sum'] = Risk_Parity.sum(1)

創(chuàng)建 Risk_Parity 的新副本而不向原始列寫入新列

To create a new copy of Risk_Parity without writing a new column to the original

Risk_Parity.assign(Sum= Risk_Parity.sum(1))

<小時>

還要注意,我將列命名為 Sum 而不是 sum.我這樣做是為了避免與我用來創(chuàng)建列的名為 sum 的相同方法發(fā)生沖突.


Notice also, that I named the column Sum and not sum. I did this to avoid colliding with the very same method named sum I used to create the column.

只包含數(shù)字列...但是,sum 無論如何都知道要跳過非數(shù)字列.

To only include numeric columns... however, sum knows to skip non-numeric columns anyway.

RiskParity.assign(Sum=RiskParity.select_dtypes(['number']).sum(1))
# same as
# RiskParity.assign(Sum=RiskParity.sum(1))

             VCIT   VCLT    PCY   RWR    IJR    XLU    EWL     Sum
Date                                                              
2017-01-31  21.70  11.73   9.59  8.28   5.06   7.01   7.95   71.33
2017-02-28  19.84  10.75   9.58  7.55   5.07   7.45   7.95   68.19
2017-03-31  19.99  10.75   9.59  7.37   5.02   7.40   7.65   67.79
2017-04-30  18.90  11.10  10.02  9.67   5.90   7.40  11.28   74.27
2017-05-31  63.96  23.67  46.02  9.92  15.23  12.34  20.41  191.55

這篇關于在 Python Dataframe 中對行求和的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 拍真实国产伦偷精品 | 欧美视频一区二区三区 | 无码一区二区三区视频 | 最新中文字幕在线播放 | 色黄爽 | 日韩在线日韩 | 精品成人av | 久久久久久亚洲精品 | 亚洲高清一区二区三区 | 国产在线精品一区二区三区 | 日韩在线三级 | 麻豆一区二区三区 | 精品一区国产 | 国产精品久久久久久久7777 | 国产9999精品 | 欧美手机在线 | 成人网av| 国产99久久久国产精品下药 | 久久久成人一区二区免费影院 | 亚洲婷婷六月天 | 国产一区欧美 | 欧美1区| 成人av久久 | 久久1区 | 国产乱肥老妇国产一区二 | 日批日韩在线观看 | 久久爱一区 | 91一区二区| 日韩欧美国产一区二区三区 | 国产一级特黄真人毛片 | 亚洲一区二区三区视频 | a级在线观看 | 久久小视频 | 天天操操| 亭亭五月激情 | 精品在线播放 | 91中文字幕在线 | 国产中文在线观看 | 久久久久亚洲av毛片大全 | 美国一级毛片a | 青青草视频免费观看 |