Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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 基于其他列的值填充pandas列的简单方法_Python_Pandas_Dataframe - Fatal编程技术网

Python 基于其他列的值填充pandas列的简单方法

Python 基于其他列的值填充pandas列的简单方法,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个熊猫数据框,有3列,如下所示: a b c 0 1 1 10 1 2 12 10 2 16 13 10 3 9 16 10 在c列中,我希望每行最多有3个数字,因此它应该如下所示: a b c 0 1 1 10 1 2 12 12 2 16 13 16 3 9 16 16 我可以用for循环来实现这一点,但我想知道是否有更简单的方法来实现这一点?使用

我有一个熊猫数据框,有3列,如下所示:

      a   b   c
0      1  1  10
1     2  12  10
2    16  13  10
3      9 16  10
在c列中,我希望每行最多有3个数字,因此它应该如下所示:

      a   b   c
0      1  1  10
1     2  12  12
2    16  13  16
3      9 16  16
我可以用for循环来实现这一点,但我想知道是否有更简单的方法来实现这一点?

使用df.maxaxis=1

或者,分配以返回新的数据帧

In [1812]: df.assign(c=df.max(axis=1))
Out[1812]:
    a   b   c
0   1   1  10
1   2  12  12
2  16  13  16
3   9  16  16
使用df.maxaxis=1

或者,分配以返回新的数据帧

In [1812]: df.assign(c=df.max(axis=1))
Out[1812]:
    a   b   c
0   1   1  10
1   2  12  12
2  16  13  16
3   9  16  16