行中的组值在一起并为它们分配一个互构值
嗨,我有看起来像这样的数据框:
a | b | c | d |
---|---|---|---|
ab | x | 10 | 1a |
fh | y | 15 | 4h |
ky | z | 20 | 6f |
da | x | 10 | 1a |
我想创建一个新列,其中互动(从1/0开始)分配给所有在b,c,d中具有相同值的行,
例如:row1,4在“ val”列中的整数相同。
输出应该看起来像这样
a | b | c | d | val |
---|---|---|---|---|
ab | x | 10 | 1a | 1 |
fh | y | 15 | 4H | 2 |
ky | z | 20 | 6f | 3 |
da | x | 10 | 1a | 1 |
Hi I have dataframe that looks like this:
A | B | C | D |
---|---|---|---|
AB | X | 10 | 1a |
FH | Y | 15 | 4h |
KY | Z | 20 | 6f |
DA | X | 10 | 1a |
I want to create a new column where an interger (starting from 1/0) is assigned to all rows that have same value in column B,C,D
for eg : row1,4 will be same integer in column 'Val' that is created.
Output should look something like this
A | B | C | D | Val |
---|---|---|---|---|
AB | X | 10 | 1a | 1 |
FH | Y | 15 | 4h | 2 |
KY | Z | 20 | 6f | 3 |
DA | X | 10 | 1a | 1 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
pd.factorize
与frozenset
Use
pd.factorize
with afrozenset