Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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
Dataframe在Python中使用for循环时获得转置_Python_Pandas_Dataframe_For Loop - Fatal编程技术网

Dataframe在Python中使用for循环时获得转置

Dataframe在Python中使用for循环时获得转置,python,pandas,dataframe,for-loop,Python,Pandas,Dataframe,For Loop,我一直在处理一个数据集,其中数据帧在从for循环执行后尝试打印时会发生转置 还希望将来自for循环的已处理数据附加到单独的数据框中,该数据框可用于以后保存在Excel文件中 输入数据: name Joining_Date age Contact col4 col5 flag NKJ 4/26/2021 48! 96754789 8886H AHBZ Not feasible Tom 26.4.2021

我一直在处理一个数据集,其中数据帧在从for循环执行后尝试打印时会发生转置

还希望将来自for循环的已处理数据附加到单独的数据框中,该数据框可用于以后保存在Excel文件中

输入数据:

name  Joining_Date      age   Contact    col4   col5         flag

NKJ    4/26/2021        48!   96754789   8886H  AHBZ        Not feasible
Tom    26.4.2021        27    98468300   ^686H  ANKZ        feasible
Mike   2/27/2021        28@   78915359   3256H  AK9Z        Not feasible
Steve  3/11/2021        23@   7891HI59   3256H  AK5Z        feasible
JKN    2/12/2021        35    96451188   3566H  NK4Z        Not feasible
预期产出

name  Joining_Date      age   Contact    col4   col5         flag

NKJ    2021-4-26        48    96754789   8886H  AHBZ        feasible
Tom    26.4.2021        27    98468300   ^686H  ANKZ        feasible
Mike   2021-2-27        28    78915359   3256H  AK9Z        feasible
Steve  3/11/2021        23@   7891HI59   3256H  AK5Z        feasible
JKN    2021-2-12        35    96451188   3566H  NK4Z        feasible
代码:

使用上面的代码将输出作为

name           NKJ
Joining_Date   2021-01-26
age            48
Contact        96754789
col4           8886H
col5           AHBZ
flag           
当尝试将内部循环打印为print(file.head())时,它会以转置形式一个接一个地打印所有数据

请建议

name           NKJ
Joining_Date   2021-01-26
age            48
Contact        96754789
col4           8886H
col5           AHBZ
flag