简体   繁体   中英

smoothing curve with pandas and interpolate not modifying data

I'm sure I'm not doing this right. I have a dataframe with a series of data, basically year and a value. I want to smoothen the curve and was looking to use spline to test results.

Basically I was trying to take a column and return the new datapoints into another column:

df['smooth'] = df['value'].interpolate(method='spline', order=3, s=0.)

but the results between smooth and value are the same.

        value  periodDate     smooth  diffSmooth
6   422976.72        2019  422976.72         0.0
7   190865.94        2018  190865.94         0.0
8   188440.89        2017  188440.89         0.0
9   192481.64        2016  192481.64         0.0
10  191958.64        2015  191958.64         0.0
11  681376.60        2014  681376.60         0.0

Any suggestions of what I'm doing wrong?

According to the Pandas docs , the interpolate function fills missing values in a sequence, so for example linear interpolation would be [0, 1, NaN, 3] -> [0, 1, 2, 3]. In short, you're using the wrong function. If you want to fit a spline, sklearn or scipy or numpy may be better bets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM