Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将满足一定条件的列的标题返回到表中的新列_Python_Pandas - Fatal编程技术网

Python 如何将满足一定条件的列的标题返回到表中的新列

Python 如何将满足一定条件的列的标题返回到表中的新列,python,pandas,Python,Pandas,对于下面的dataframe,如何将大于1的列的标题名返回到名为“备注”的新列 希望输出如下 A B C Remark 0 1 1 2 C 1 2 2 2 A,B,C 2 1 3 1 B 3 4 5 2 A,B,C 提前感谢您按列名称使用带分隔符的布尔数据框,最后删除,: df['Remark'] = df.gt(1).dot(df.columns + ',').str[:-1] print (df)

对于下面的dataframe,如何将大于1的列的标题名返回到名为“备注”的新列

希望输出如下

    A   B   C   Remark
0   1   1   2   C
1   2   2   2   A,B,C 
2   1   3   1   B
3   4   5   2   A,B,C
提前感谢您

按列名称使用带分隔符的布尔
数据框
,最后删除

df['Remark'] = df.gt(1).dot(df.columns + ',').str[:-1]
print (df)
   A  B  C Remark
0  1  1  2      C
1  2  2  2  A,B,C
2  1  3  1      B
3  4  5  2  A,B,C
详细信息

print (df.gt(1))
       A      B      C
0  False  False   True
1   True   True   True
2  False   True  False
3   True   True   True

print (df.gt(1).dot(df.columns + ','))
0        C,
1    A,B,C,
2        B,
3    A,B,C,
dtype: object

,非常感谢。
print (df.gt(1))
       A      B      C
0  False  False   True
1   True   True   True
2  False   True  False
3   True   True   True

print (df.gt(1).dot(df.columns + ','))
0        C,
1    A,B,C,
2        B,
3    A,B,C,
dtype: object