Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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转换csv_Python_Pandas - Fatal编程技术网

Python 使用pandas转换csv

Python 使用pandas转换csv,python,pandas,Python,Pandas,我有一个csv文件,需要根据这两列进行转换 示例代码段: a,UUID_ID,c,d 1,UUID1,3,2 1,UUID2,'add',2 3,UUID3,23-2-2018,5 a,UUID_ID,c,d 1,UUID1,3, # here I put nan value for d column. So # in output it should still consider that 1,UUID2,'add', # here I put nan value for d

我有一个csv文件,需要根据这两列进行转换

示例代码段:

a,UUID_ID,c,d
1,UUID1,3,2
1,UUID2,'add',2
3,UUID3,23-2-2018,5
a,UUID_ID,c,d
1,UUID1,3,  # here I put nan value for d column. So 
   # in output it should still consider that
1,UUID2,'add',   # here I put nan value for d column. So
   # in output it should still consider that
3,UUID3,23-2-2018,5
预期输出如下所示:

a,d,UUID1, UUID2, UUID3
1,2,2,'add',
3,5,,,23-2-2018
a,d,UUID1, UUID2, UUID3
1,,2,'add',
3,5,,,23-2-2018
我尝试将文件读入pandas并创建另一个dataframe副本,但不知道如何将它们连接在一起。有没有什么好办法来解决这个问题


跟进

示例代码段:

a,UUID_ID,c,d
1,UUID1,3,2
1,UUID2,'add',2
3,UUID3,23-2-2018,5
a,UUID_ID,c,d
1,UUID1,3,  # here I put nan value for d column. So 
   # in output it should still consider that
1,UUID2,'add',   # here I put nan value for d column. So
   # in output it should still consider that
3,UUID3,23-2-2018,5
预期输出如下所示:

a,d,UUID1, UUID2, UUID3
1,2,2,'add',
3,5,,,23-2-2018
a,d,UUID1, UUID2, UUID3
1,,2,'add',
3,5,,,23-2-2018
与:


我还有一个问题,它不允许在列“a”或“d”中使用nan值。相反,它完全删除了该行。