简体   繁体   English

如何根据 python 中的行值生成 id 列?

[英]How do I generate id column based on row values in python?

It would be great if someone could help me to address below concern.如果有人可以帮助我解决以下问题,那就太好了。

在此处输入图像描述

How do I populate ID column based on values in respect row for all columns?如何根据所有列的行中的值填充 ID 列? Something like crc32 or MD5 algorithms.类似 crc32 或 MD5 算法的东西。

Using hashlib, you could take the dictionary of row values and translate that into an md5 hash.使用 hashlib,您可以获取行值字典并将其转换为 md5 hash。

import hashlib

df['Id'] = [hashlib.md5(str(x).encode('utf-8')).hexdigest() for x in df.T.to_dict().values()]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何基于另一个列python获取列的值 - How do i get values of a column based on another column python 如何根据同一列中的先前值生成列中的值? - How do I generate values in a column based on former values in the same column? 如何使用 Python 在 Pandas 上生成一个新列以生成具有对话 ID 的推文超链接 - How do I generate a new column on Pandas with Python to Generate Tweet Hyperlinks with Conversation ID Python:如何检查每一行和每一列的值? - Python: How do I check for the values of each row and column? Pandas - 根据行值生成唯一 ID - Pandas - Generate Unique ID based on row values 根据列值为每一行生成摘要 - Generate summary for each row based on column values 如何基于熊猫中的两个列值对一行和上一行进行切片? - How do I slice a row and the preceding row based on two column values in pandas? PySpark:如何基于其他行值更改行+列的值 - PySpark: How do I change the value of a row+column based on the value of other row values 如何根据同一行中其他列的值返回一列的值(在值阈值内)? - How do I return values of one column (within a value threshold) based on the values of other columns in the same row? 如何根据多个条件计算多列中的值并明智地创建新列? - How do i count values in multiple columns based on multiple criteria and create a new column row wise?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM