在python中重新排列草率的CSV文件?

时间:2016-01-14 15:50:10

标签: python csv transpose

我收到了一些非常草率的CSV数据。我想在python中安排它,但有一些东西让我循环。下面是CSV文件的标题和示例第一行。

PATIENT,MD,REFMD,DIAGNOSIS_HISTORY,AVAILABLE_STUDIES
"last name, first name <odd character return>
name id <odd character return>
name age",doctor name <no quotes>
doctor name 2 <no quotes>,"referring doctor last name, first name ",studies <no quotes>,"history line 1
history line 2<odd character return>
history line 3"<odd character return>

这就是我希望数据在最终结果中的样子。

PATIENT,PATIENT ID, PATIENT AGE,MD1, MD2,REFMD,DIAGNOSIS_HISTORY,AVAILABLE_STUDIES
"name, name","name id","name age","doctor name","doctor name2","referring doctor last name, first name","studies","history line 1 history line history line 3"

我知道我可以用一些for循环进行大部分重新排列,但是在名字,医生姓名和历史以及字符串周围缺少引号之后,角色会回复我。

有关如何在转置内容之前清理数据的任何建议吗?

0 个答案:

没有答案