python-列出熊猫数据框

时间:2018-10-25 11:16:46

标签: python python-3.x pandas list dataframe

我有字符串列表。 每个字符串都是带有逗号分隔符的句子。

RMCs = [
        '$GPRMC,222112.184,A,3713.681121,N,12205.707716,W,2.580,44.9,181018,,,A,V*33', 
        '$GPRMC,222113.150,A,3713.804392,N,12205.729394,W,1.435,64.5,181018,,,A,V*32', 
        '$GPRMC,222114.153,A,3713.833715,N,12205.736514,W,0.180,323.4,181018,,,A,V*02', 
        '$GPRMC,222115.157,A,3713.834953,N,12205.735842,W,0.374,8.8,181018,,,A,V*0E', 
        '$GPRMC,222116.163,A,3713.834541,N,12205.733602,W,0.240,346.6,181018,,,A,V*08', 
        '$GPRMC,222117.163,A,3713.833123,N,12205.734873,W,0.664,238.3,181018,,,A,V*0E', 
        '$GPRMC,222118.166,A,3713.833402,N,12205.733397,W,0.242,308.0,181018,,,A,V*05'
       ]

我想用逗号分隔每行并将其放入Pandas数据框。 预期的输出应如下表所示:

1  $GPRMC  222112.184  A  3713.681121  N  12205.707716  W  2.580  44.9  181018  NaN  NaN  A  V*33
2  $GPRMC  222113.150  A  3713.804392  N  12205.729394  W  1.435  64.5  181018  NaN  NaN  A  V*32
3  $GPRMC  222114.153  A  3713.833715  N  12205.736514  W  0.180 323.4  181018  NaN  NaN  A  V*02'
.
.
n  $GPRMC  ................................................................

**如果需要,我可以添加标题。

尝试了很多方法,但是找到了最有效,最干净的方法。

请协助。

1 个答案:

答案 0 :(得分:1)

"Powershell -noexit -File ""C:\Script\VBA Testing\Testing.ps1""" 构造函数与列表理解和DataFrame一起使用:

split

如果还要替换df = pd.DataFrame([x.split(',') for x in RMCs]) print (df) 0 1 2 3 4 5 6 7 8 \ 0 $GPRMC 222112.184 A 3713.681121 N 12205.707716 W 2.580 44.9 1 $GPRMC 222113.150 A 3713.804392 N 12205.729394 W 1.435 64.5 2 $GPRMC 222114.153 A 3713.833715 N 12205.736514 W 0.180 323.4 3 $GPRMC 222115.157 A 3713.834953 N 12205.735842 W 0.374 8.8 4 $GPRMC 222116.163 A 3713.834541 N 12205.733602 W 0.240 346.6 5 $GPRMC 222117.163 A 3713.833123 N 12205.734873 W 0.664 238.3 6 $GPRMC 222118.166 A 3713.833402 N 12205.733397 W 0.242 308.0 9 10 11 12 13 0 181018 A V*33 1 181018 A V*32 2 181018 A V*02 3 181018 A V*0E 4 181018 A V*08 5 181018 A V*0E 6 181018 A V*05 字符串:

empty