2016-09-13 18 views
1

我试图使用熊猫提供的插入功能,here但由于某种原因,无法让我的系列调整到正确的值。我把它们铸成了float64,但是这似乎没有帮助。任何建议?无法正确使用熊猫插入一系列

代码:

for feature in price_data: 
    print price_data[feature] 
    print "type:" 
    print type(price_data[feature]) 
    newSeries = price_data[feature].astype(float).interpolate() 
    print "newSeries: " 
    print newSeries 

输出:

0 178.9000 
1  0.0000 
2 178.1200 
Name: open_price, dtype: object 
type: 
<class 'pandas.core.series.Series'> 
newSeries: 
0 178.90 
1  0.00 
2 178.12 
Name: open_price, dtype: float64 

回答

0

的问题是,没有什么可以插值。我假设你想插入零值的地方。在这种情况下,用np.nan替换零并插入。一种方法可以做到这一点

price_data.where(price_data != 0, np.nan).interpolate() 

0 178.90 
1 178.51 
2 178.12 
Name: open_price, dtype: float64 
+0

完全忽略了......感谢您的时间! – user3547551