我有一个类似python pandas的数据框架
>>> df
classification like
0 flower 1
1 flower 0
2 flower 0
3 adventure 1
4 adventure 1
我想创建一个输出数据帧
>>> df
classification like liked
0 flower 1 True
1 flower 0 False
2 flower 0 False
3 adventure 1 True
4 adventure 1 True
我将在输入数据帧上“应用”python lambda函数,如下所示:
>>> df['like'].apply(lambda x: x == 1)
但是我在“喜欢”栏下得到了所有的“错误”
>>> df
classification like liked
0 flower 1 False
1 flower 0 False
2 flower 0 False
3 adventure 1 False
4 adventure 1 False
任何快速的建议都会有帮助。
>>> df['like'].astype(int)
0 1
1 0
2 0
3 1
4 1
Name: like, dtype: int32
@耶斯拉利
>>> df['liked'] = df['like'].astype(bool)
>>> df
classification like liked
0 flower 1 True
1 flower 0 True
2 flower 0 True
3 adventure 1 True
4 adventure 1 True
@Jezrael:数据类型
>>> df.dtypes
classification object
like object
liked bool
dtype: object