簡體   English   中英

如何在 dataframe 的單行中分配多個值?

[英]How to assign multiple values in a single row of a dataframe?

我想在一行中顯示特定項目的多個值。

我的 dataframe df=

**|Item| assigned|**
|one | raju    |
|one | sanket  |
|two | vinay   |
|two | chandu  |

我想把它顯示為

  **|Item| assigned       |**
    |one | raju ,sanket   |
    |two | vinay,chandu   |

如果有人知道上述查詢,請告訴我。 提前致謝。

有了這個 dataframe,


df = pd.DataFrame({"Item": "one one two two".split(), 
                   "assigned": "raju sanket vinay chandu".split()})

你可以做

df.groupby("Item").agg(",".join)

要得到

          assigned
Item
one    raju,sanket
two   vinay,chandu

暫無
暫無

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

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