我要转换三个字符串。

 row='A;B;C'

 col='aaa,bbb,ccc;aaa,bbb,abc;aaa,bbb,ccc'

 val='99,80,90;100,100,100;90,90,90'


我想在Python中将String转换为DataframeMatrix

   aaa  bbb   ccc   abc

A  99   80    90    NaN

B  100  100   NaN   100

C  90   90    90    NaN



如何将上述字符串或任何其他字符串转换为Dataframe

最佳答案

这应该可以解决https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

您有一些不一致的定界符,我已将其替换为,

row='A,B,C'
col='aaa,bbb,ccc,aaa,bbb,abc,aaa,bbb,ccc'
val='99,80,90,100,100,100,90,90,90'
buffer = ""
buffer += row + "\n" + col+ "\n"+val
pandas.read_csv(buffer)

关于python - 在Python中将多个字符串转换为数据帧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60374611/

10-14 19:02