日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

python中where函数_如何在python中基于Where函数获取两列值

發布時間:2023/11/27 生活经验 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中where函数_如何在python中基于Where函数获取两列值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題是:

基于user_id列,我想得到rating和{}列的值。可能有多個條目具有相同的用戶標識。我希望獲取具有rating和product_id列值的所有用戶記錄,但對于用戶未對電影進行評級的電影,應將其顯示為Nan,但仍應檢索product_id。下表提供了一些數據。在| product_id | user_id | user_name | rating |

|-------------|-----------------|----------------------------------------------|--------|

| B0009XRZ92 | A2JFZLAUG3YFQ7 | Entropy Babe "EB" | 5 |

| B0009XRZ92 | A22HGAAO8KZ2N3 | R. Metzelar | 5 |

| B000067A8B | A2NJO6YE954DBH | Lawrance M. Bernabo | 4 |

| B0009XRZ92 | A3HE4MYMWK4AER | Rebecca M. Eddy "Foster Mom and Untbunny" | 5 |

| B003A3R3ZY | A9A2PR663ED1V | Roger D. Goff | 5 |

| B0009XRZ92 | A2MRZDJF90JC1U | Suzanne K. Armstrong "Suzy Q" | 5 |

| B0009XRZ92 | A2YNBDT3170PCR | C. O'Hern | 5 |

| B0009XRZ92 | A10VJ7BDVCPKEZ | Carol S. Bottom | 5 |

| B0009XRZ92 | AAAQO894MG80B | Paul J. Michko | 5 |

| B00067BBQE | A9A2PR663ED1V | Roger D. Goff | 5 |

| B0009XRZ92 | A31S5QUMFR8NH2 | Dana L. Jordan "Mom of Twins" | 5 |

| B0009XRZ92 | A2DS24DHXUH0GM | Gaz Rev(iewer) | 4 |

| B00006AUMZ | A2NJO6YE954DBH | Lawrance M. Bernabo | 4 |

| B0009XRZ92 | A16FRHL2ZC7EUR | M. Claytor | 5 |

| B0009XRZ92 | A3AV8R0A62PP1N | MARCUSHELBLINZ "mmmacman" | 5 |

| B0009XRZ92 | A3QN84C38DE9FU | Gillian M. Kratzer | 5 |

| B0009XRZ92 | A36MLTLVQFEQYL | Yossarian "alienated socialist" | 5 |

| B00006AUMD | A2NJO6YE954DBH | Lawrance M. Bernabo | 4 |What I want to do is:

To take one user_id at a time and display the rating and product_id

columns value for that user for all the movies in the table and if the

user didn't rate some movies then the record should be displayed with

the product_id value and rating as Nan and the whole process should be repeated for all the users.

例如,user_id: A2NJO6YE954DBH的記錄如下所示:

^{pr2}$

我試著用Pandas庫來編寫代碼,但還是忍不住。這是我所做的一切,但它沒有輸出我想要的。在import pandas as pd

df =pd.read_csv('out.csv')

unique_users=df.user_id.unique()

for x, y in enumerate(unique_users):

print(df[['rating','product_id']].where(df.user_id==y))

請幫幫我。。謝謝

總結

以上是生活随笔為你收集整理的python中where函数_如何在python中基于Where函数获取两列值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。