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

Python Pandas:計算每行數據幀中特定值的頻率?

Python Pandas: Counting the frequency of a specific value in each row of dataframe?(Python Pandas:計算每行數據幀中特定值的頻率?)
本文介紹了Python Pandas:計算每行數據幀中特定值的頻率?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個數據框 df:

I have a dataframe df:

domain               country     out1 out2 out3
oranjeslag.nl           NL          1    0   NaN    
pietervaartjes.nl       NL          1    1    0
andreaputting.com.au    AU          NaN  1    0 
michaelcardillo.com     US          0    0    NaN

我想定義兩列 sum_0 和 sum_1 并計算每行列 (out1,out2,out3) 中 0 和 1 的數量.所以預期的結果是:

I would like to define two columns sum_0 and sum_1 and count the number of 0s and 1s in columns (out1,out2,out3),per row. So expected results would be:

domain               country     out1 out2 out3   sum_0  sum_1
oranjeslag.nl           NL          1    0   NaN    1      1
pietervaartjes.nl       NL          1    1    0     1      2
andreaputting.com.au    AU          NaN  1    0     1      1
michaelcardillo.com     US          0    0    NaN   2      0

我有這個計算1個數的代碼,但我不知道如何計算0個數.

I have this code for counting the number of 1s, but I do not know how to count the number of 0s.

df['sum_1'] = df[['out_1','out_2','out_3']].sum(axis=1)

有人可以幫忙嗎?

推薦答案

你可以為每個條件調用sum1條件很簡單,只是一個直接的axis=1 上的 sum,第二次您可以將 df 與 0 值進行比較,然后像以前一樣調用 sum:

You can call sum for each condition, the 1 condition is simple just a straight sum on axis=1, for the second you can compare the df against 0 value and then call sum as before:

In [102]:
df['sum_1'] = df[['out1','out2','out3']].sum(axis=1)
df['sum_0'] = (df[['out1','out2','out3']] == 0).sum(axis=1)
df

Out[102]:
                 domain country  out1  out2  out3  sum_0  sum_1
0         oranjeslag.nl      NL     1     0   NaN      1      1
1     pietervaartjes.nl      NL     1     1     0      1      2
2  andreaputting.com.au      AU   NaN     1     0      1      1
3   michaelcardillo.com      US     0     0   NaN      2      0

這篇關于Python Pandas:計算每行數據幀中特定值的頻率?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
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(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 97国产精品| 亚洲国产精品一区二区久久 | 亚洲视频在线一区 | 91亚洲精华国产 | 日韩一二区 | 色婷婷久久| 超碰精品在线 | 午夜影院视频在线观看 | 99精品国产一区二区青青牛奶 | 性色av香蕉一区二区 | 成人激情视频免费观看 | 狠狠夜夜| 国产免费福利小视频 | 激情综合五月天 | 蜜桃视频在线观看www社区 | .国产精品成人自产拍在线观看6 | 欧美中文字幕一区二区 | 久久综合婷婷 | 黄色大全免费看 | 日韩精品网站 | 韩日在线| 久久久久久国产精品 | 欧美精品网 | 成人综合一区二区 | 久久精品中文字幕 | 国产精品观看 | 成人免费在线 | 亚洲精品68久久久一区 | 中文字幕成人av | 韩日一区二区三区 | 暖暖日本在线视频 | 麻豆av在线 | 国产精品海角社区在线观看 | av在线伊人 | 国产精品成人一区二区三区夜夜夜 | 成人精品毛片 | 国产午夜精品一区二区三区嫩草 | 免费观看国产视频在线 | 亚洲欧美日韩中文字幕一区二区三区 | 亚洲综合二区 | 国产日韩欧美 |