2016-02-05 61 views
1

我有這個文件:大熊貓創建數據框 - 解析關鍵

:Product: Solar Radio Data    7day_rad.txt 
:Issued: 0922 UTC 05 Feb 2016 
# 
# Prepared by the U.S. Dept. of Commerce, NOAA, Space Weather Prediction Center 
# Please send comments and suggestions to [email protected] 
# Units: 10^-22 W/m^2/Hz 
# Missing Data: -1 
# 
# Daily local noon solar radio flux values - Updated once an hour 
# 
    Freq Learmonth San Vito Sag Hill Penticton Penticton Palehua Penticton 
    MHZ 0500 UTC 1200 UTC 1700 UTC 1700 UTC 2000 UTC 2300 UTC 2300 UTC 


2016 Jan 30 
    245  20  17  17   -1   -1  12  -1 
    410  38  34  37   -1   -1  35  -1 
    610  56  -1  56   -1   -1  50  -1 
    1415  104  73  72   -1   -1  78  -1 
    2695  106  106  98   -1   -1  101  -1 
    2800  -1  -1  -1  105  105  -1  105 
    4995  -1  149  134   -1   -1  145  -1 
    8800  287  269  261   -1   -1  275  -1 
15400  514  573  536   -1   -1  515  -1 


2016 Jan 31 
    245  21  18  20   -1   -1  32  -1 
    410  39  17  38   -1   -1  46  -1 
    610  58  -1  56   -1   -1  60  -1 
    1415  91  74  72   -1   -1  78  -1 
    2695  102  103  97   -1   -1  100  -1 
    2800  -1  -1  -1  102  101  -1  100 
    4995  -1  146  135   -1   -1  138  -1 
    8800  278  268  262   -1   -1  272  -1 
15400  513  568  530   -1   -1  521  -1 


2016 Feb 1 
    245  25  21  21   -1   -1  35  -1 
    410  45  40  40   -1   -1  49  -1 
    610  66  -1  59   -1   -1  63  -1 
    1415  65  72  68   -1   -1  78  -1 
    2695  99  101  90   -1   -1  97  -1 
    2800  -1  -1  -1  100  100  -1  100 
    4995  -1  140  131   -1   -1  139  -1 
    8800  278  258  266   -1   -1  275  -1 
15400  508  565  528   -1   -1  526  -1 


2016 Feb 2 
    245  23  20  21   -1   -1  36  -1 
    410  45  68  40   -1   -1  48  -1 
    610  68  -1  60   -1   -1  61  -1 
    1415  72  73  69   -1   -1  80  -1 
    2695  98  98  93   -1   -1  102  -1 
    2800  -1  -1  -1  102  102  -1  103 
    4995  -1  141  131   -1   -1  141  -1 
    8800  284  255  268   -1   -1  276  -1 
15400  510  568  537   -1   -1  526  -1 


2016 Feb 3 
    245  34  -1  20   -1   -1  36  -1 
    410  47  -1  41   -1   -1  50  -1 
    610  70  -1  63   -1   -1  66  -1 
    1415  68  76  76   -1   -1  86  -1 
    2695  105  -1  106   -1   -1  112  -1 
    2800  -1  -1  -1  113  112  -1  112 
    4995  -1  -1  140   -1   -1  152  -1 
    8800  284  -1  260   -1   -1  284  -1 
15400  516  -1  455   -1   -1  535  -1 


2016 Feb 4 
    245  -1  23  21   -1   -1  46  -1 
    410  -1  43  43   -1   -1  54  -1 
    610  -1  -1  65   -1   -1  68  -1 
    1415  -1  84  81   -1   -1  90  -1 
    2695  -1  114  120   -1   -1  118  -1 
    2800  -1  -1  -1  125  123  -1  120 
    4995  -1  162  154   -1   -1  158  -1 
    8800  -1  276  273   -1   -1  283  -1 
15400  -1  564  523   -1   -1  547  -1 


2016 Feb 5 
    245  34  -1  -1   -1   -1  -1  -1 
    410  52  -1  -1   -1   -1  -1  -1 
    610  78  -1  -1   -1   -1  -1  -1 
    1415  84  -1  -1   -1   -1  -1  -1 
    2695  115  -1  -1   -1   -1  -1  -1 
    2800  -1  -1  -1   -1   -1  -1  -1 
    4995  -1  -1  -1   -1   -1  -1  -1 
    8800  295  -1  -1   -1   -1  -1  -1 
15400  508  -1  -1   -1   -1  -1  -1 

,現在我需要創建數據幀在那裏我可以閱讀最新數據從pentiction時間......我可以創建數據幀,並與日期時間解析它但在這種情況下不工作...

任何建議請問?

+0

數據塊始終10行? – jezrael

+0

hello jezrael ...我的救世主: - )...是總是10行... –

+0

列總是'8'? – jezrael

回答

1

嘗試read_csv

#after testing replace io.StringIO(temp) to filename 
df = pd.read_csv(io.StringIO(temp), 
       sep="\s+", 
       skip_blank_lines=True, 
       index_col=None, 
       skiprows=14, 
       header=None, 
       names=['Freq','a','b','c','d','e','f','g']) 
print df 

    Freq a b c d e f g 
0 2016 Jan 30 NaN NaN NaN NaN NaN 
1  245 20 17 17 -1 -1 12 -1 
2  410 38 34 37 -1 -1 35 -1 
3  610 56 -1 56 -1 -1 50 -1 
4 1415 104 73 72 -1 -1 78 -1 
5 2695 106 106 98 -1 -1 101 -1 
6 2800 -1 -1 -1 105 105 -1 105 
7 4995 -1 149 134 -1 -1 145 -1 
8 8800 287 269 261 -1 -1 275 -1 
9 15400 514 573 536 -1 -1 515 -1 
10 2016 Jan 31 NaN NaN NaN NaN NaN 
11 245 21 18 20 -1 -1 32 -1 
12 410 39 17 38 -1 -1 46 -1 
13 610 58 -1 56 -1 -1 60 -1 
14 1415 91 74 72 -1 -1 78 -1 
15 2695 102 103 97 -1 -1 100 -1 
+0

非常感謝你... –