2017-07-31 18 views
0

我有这样的数据了很多年,并且需要绘制了不同年份的误差图中,1993年与如何转换“对象”,以数值包括南

fm93 = fmm[(fmm.Year == 1993)] 

选择则FM93数据帧

Year moB m1  std1 co1 min1 max1 m2S std2S co2S min2S max2S 
1993 1 296.42 18.91 31 262.4 336  -- -- --  --  -- 
1993 2 280.76 24.59 28 239.4 329.3 -- --  -- -- -- 
1993 3 271.41 19.16 31 236.4 304.8 285.80 20.09 20 251.6 319.7 
1993 4 287.98 22.52 30 245.9 341 296.75 21.77 27 261.1 345.7 
1993 5 287.05 30.79 30 229.2 335.7 300.06 27.64 24 249.5 351.8 
1993 6 288.65 11.29 4 275.9 301.9 263.70 73.40 7 156.5 361 
1993 7 280.11 36.01 12 237 363 302.67 26.39 22 262.9 377.1 
1993 8 296.51 34.55 31 234.8 372.9 305.85 39.95 28 234.1 417.9 
1993 9 321.31 34.54 25 263.8 396 309.01 42.52 29 205.9 403.2 
1993 10 315.80 8.63 2 309.7 321.9 288.65 35.86 31 230.9 345.4 
1993 11 288.26 24.07 30 231.4 322.8 297.99 23.81 28 238 336.5 
1993 12 296.87 18.31 31 257.6 331.5 303.02 20.02 29 265.7 340.7 

当我尝试绘图MOB,M1与犯错STD1出现错误

ValueError: err must be [ scalar | N, Nx1 or 2xN array-like ] 

这是因为价值观是“对象” ..

array([[1993, 1, '296.42', '18.91', '31', '262.4', '336', '--', '--', '--', 
    '--', '--'], 
    [1993, 2, '280.76', '24.59', '28', '239.4', '329.3', '--', '--', 
    '--', '--', '--'], 
    [1993, 3, '271.41', '19.16', '31', '236.4', '304.8', '285.80', 
    '20.09', '20', '251.6', '319.7'], 
    [1993, 4, '287.98', '22.52', '30', '245.9', '341', '296.75', 
    '21.77', '27', '261.1', '345.7'], 
    [1993, 5, '287.05', '30.79', '30', '229.2', '335.7', '300.06', 
    '27.64', '24', '249.5', '351.8'], 
    [1993, 6, '288.65', '11.29', '4', '275.9', '301.9', '263.70', 
    '73.40', '7', '156.5', '361'], 
    [1993, 7, '280.11', '36.01', '12', '237', '363', '302.67', '26.39', 
    '22', '262.9', '377.1'], 
    [1993, 8, '296.51', '34.55', '31', '234.8', '372.9', '305.85', 
    '39.95', '28', '234.1', '417.9'], 
    [1993, 9, '321.31', '34.54', '25', '263.8', '396', '309.01', 
    '42.52', '29', '205.9', '403.2'], 
    [1993, 10, '315.80', '8.63', '2', '309.7', '321.9', '288.65', 
    '35.86', '31', '230.9', '345.4'], 
    [1993, 11, '288.26', '24.07', '30', '231.4', '322.8', '297.99', 
    '23.81', '28', '238', '336.5'], 
    [1993, 12, '296.87', '18.31', '31', '257.6', '331.5', '303.02', 
    '20.02', '29', '265.7', '340.7']], dtype=object) 

我尝试用

fm93_1 = fm93.astype('float64', raise_on_error = False) 

但问题仍然....如何转换楠值转换该数据(“ - ”)或忽略绘制我结果如何? 在此先感谢

回答

0

首先,您应该尝试在' - '之后绘制数据样本以查看是否可以生成一个绘图。你可以试试:

# This should plot from row 3 onwards, omitting row 1 and 2 
df.iloc[3:].plot() 

假设 ' - ' 的问题,你可以用replace np.NaN。 NaN值未被绘制。

df.replace('--', np.NaN, inplace=True) 
df.plot() 

另一种方式是选择DF不包含 ' - ':

mask = df[df == '--'].any(axis=1) # Check if row contains '--' 
valid_indexes = df[mask == False].index # Return index for rows w/o '--' 

df.iloc[valid_indexes].plot() 
+0

第一建议的错误:AttributeError的: 'numpy.dtype' 对象有没有属性' convert_objects'出现 – Istari

相关问题