简体   繁体   中英

How to extrapolate the given data to fill NaN values using Python?

I wish to fill the NaN values with apt extrapolation. I think curve fit method will not be apt as I have no clue about the equation of curve from the given points. I got these values from MPU. Can anyone suggest me a best way to extrapolate the values to fill NaN positions using Python?

mean_acc  timestamp     x_acc   x_gyro  y_acc   y_gyro  z_acc   z_gyro

  1.00     1143            0.96     -1.22     0.16     2.81  0.24  0.24

  1.17    1646             1.15     -7.26   0.14    4.88    0.18    -0.06

  1.02     2149            1.00     8.36    0.15    11.78   0.12    3.11

   0.98     2652           0.96     -8.30   0.15    2.01    0.11    -2.01

   1.05     3155           0.94     -4.21   0.17    3.42    0.42    -2.93

   1.01     3658           1.00     2.75    0.12    4.64    0.05    5.13

    NaN     4161            NaN     NaN     NaN     NaN     NaN     NaN

    NaN     4664            NaN     NaN     NaN     NaN     NaN     NaN

    NaN     5167             NaN    NaN     NaN     NaN     NaN     NaN

    NaN     5670             NaN    NaN     NaN     NaN     NaN     NaN

By reading your question I had confusion about what you really wanted as answer -

  1. Different methods to extrapolate or
  2. How to fill NA values to the columns with using particular extrapolation methods.

However I'll try to answer both.

mean_acc, x_acc, y_acc, z_acc null values can be filled by their mean values. For y_gyro convert the existing into Log Transforms and then extrapolate mean of Log values and then invert the Log transformation to get the required.

Try plotting the remaining fields and try to find a relation that can be used to extrapolate the NULL values in the remaining columns.

  1. Extrapolating the null values in pandas.

    X['mean_acc'].fillna(X['mean_acc'].mean(), inplace=True)

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