Search code examples
pythondata-analysis

To fit polynomial function to fill the NaN value in my data frame


enter image description hereGood evening everyone, I have a data frame with 226 columns and 1110 instances. Some values in some rows have nan values so I'm goin to fill these values by condition. First, the minimum value for start filling should be the latest value before nan value in each row. Second, the maximum value should be the latest column and if the last value before first nan is equal to maximum the nan values will fill with maximum. There is final code that shows the data frame with nan values. Because the main data set is to big I won't be able to upload it and I just share a photo of my out put in python.

# hi_1_df = health indecatore 1 data frame
hi_1_df = pd.DataFrame(pivoted_df.values, columns=[f'v{i+1}' for i in range(pivoted_df.shape[1])], index=pivoted_df.index)

capacity_df= cs2_df.groupby('Cycle_ID')['Max_Capacity'].max()

hi_1_df['Max_voltage']=cs2_df['Voltage(V)'].max()

# Merge max_capacity_df into app_df based on 'Cycle_ID'
hi_1_df = hi_1_df.merge(capacity_df, left_index=True, right_index=True, how='left')

hi_1_df

I expect the value of nan to be filled with correct values using the appropriate polynomial function where NaN is replaced with the appropriate values that are incremented in order.


Solution

  • Use the .ffill() function to forward fill values from left to right. Reference

    df.ffill(axis = 1)