df = pd.DataFrame({'info':[[1,2,3], [4,5,6], 'str224']})
df['info_str'] = df['info'].astype(str)
print(df['info_str'][0])
print(type(df['info_str'][0]))
print(df['info_str'].apply(lambda x: x if x in df['info'].tolist() else pd.eval(x))[0])
print(type(df['info_str'].apply(lambda x: x if x in df['info'].tolist() else pd.eval(x))[0]))
试试这个
希望有帮助。你知道吗
使用
pandas.eval
:将
apply
与if语句一起使用:输出:
相关问题 更多 >
编程相关推荐