Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 将下一个值移动到第一个空行_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 将下一个值移动到第一个空行

Python 3.x 将下一个值移动到第一个空行,python-3.x,pandas,Python 3.x,Pandas,您好,我如何将每个值从列移动到表中的第一个空“行/单元格” 例如: Original data: A B C 0 1 NaN NaN 1 4 2 NaN 2 7 5 3 3 NaN NaN 6 Desired result: A B C 0 1 2 3 1 4 5 6 2 7 NaN NaN 谢谢 您可以使用sorted在顶部对齐非空数据 df.apply(lambda x: sorted(

您好,我如何将每个值从列移动到表中的第一个空“行/单元格”

例如:

Original data:

    A   B   C
0   1  NaN  NaN
1   4    2  NaN
2   7    5  3
3 NaN  NaN  6

Desired result:
    A   B   C
0   1   2   3
1   4   5   6
2   7 NaN  NaN


谢谢

您可以使用sorted在顶部对齐非空数据

df.apply(lambda x: sorted(x, key=pd.isnull)).dropna(how = 'all')

    A   B   C
0   1.0 2.0 3.0
1   4.0 5.0 6.0
2   7.0 NaN NaN

可以使用“排序”在顶部对齐非空数据

df.apply(lambda x: sorted(x, key=pd.isnull)).dropna(how = 'all')

    A   B   C
0   1.0 2.0 3.0
1   4.0 5.0 6.0
2   7.0 NaN NaN