AttributeError :(“系列对象没有属性'colname'”,“发生在索引0”)

时间:2019-12-21 06:51:28

标签: python pandas

import pandas as pd
df = pd.read_csv(r'C:\Users\dd\Desktop\test.csv')
df

userid  url
0   123 x.com
1   345 y.com

代码

def create_dict(row):
    return ({"userid" : row.userid ,"data": {"url": row.url}})

应用

df['out'] = df.apply(lambda row: create_dict(row), axis=1)

AttributeError :(““系列”对象没有属性“用户ID””,“发生在索引0”)

userid  url   out
0   123 x.com  {'userid':'123','url':x.com'}
1   345 y.com  {'userid':'345','url':y.com'}

0 个答案:

没有答案