0
$\begingroup$

I have a column with missing data that I need to imput. Column is called 'Bandwidth'. There is a relationship between the Bandwidth column, and another column called 'Age'. As Age increases, so does Bandwidth. I want to ffill Bandwidth, but I have to do it based on the value in Age. I have over 10k records, so there is too much data to create a dictionary. I have scoured the internet, and so far am not able to find a solution.

In the simplest form of what I want to do is this:

df.sort_values(['Age']) df['Bandwidth'].fillna(method='ffill',inplace=True)

It did fill the bandwidth, based on the'sort' of bandwidth, but not based on the Age sort. The yellow ones were filled with the data from the green ones, but as you can see, the 'Age' is random.

enter image description here

But this is what I am needing it to do... (sort by age, then fill bandwidth from the above value.)

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

Since you mentioned that there is a linear relationship between Age and Bandwidth, you could train a simple linear model i.e linear regression on your dataset to estimate the bandwidth based on Age. Once you have figured out the relationship you can use it to impute the missing bandwidths.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.