[英]How to convert a dataframe column of type string to list of type tuple
have a df with type (str)有一个类型为 (str) 的 df
name password
mark (('name', 'value passed'),)
cuban (('location', 'area geocode'),)
(('name', 'value passed'),)
is a string (('name', 'value passed'),)
是一个字符串
convert a dataframe column password
of type str to list of type tuple将 str 类型的 dataframe 列
password
转换为元组类型的列表
expected output:预期 output:
tuples_password = [(('name', 'value passed'),),(('location', 'area geocode'),)]
tried this:试过这个:
tuples = [tuple(x) for x in df.password]
Im a total noob and though Id give it a go.我是个菜鸟,虽然我给了它一个 go。
df['tuple_field'] = [tuple(eval(i)) for i in df['password']]
tuples = [x for x in df['tuple_field']]
Output: Output:
[(('name', 'value passed'),), (('location', 'area geocode'),)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.