Given a dataframe with similar columns having null values in between. How to dynamically fill nulls in the columns with non-null values from other columns without explicitly stating the names of other column names e.g. select first column category1 and fill the null rows with values from other columns of same rows?
data = {'year': [2010, 2011, 2012, 2013, 2014, 2015, 2016,2017, 2018, 2019], 'category1': [None, 21, None, 10, None, 30, 31,45, 23, 56], 'category2': [10, 21, 20, 10, None, 30, None,45, 23, 56], 'category3': [10, 21, 20, 10, None, 30, 31,45, 23, 56],} df = pd.DataFrame(data) df = df.set_index('year') df category1 category2 category3 year 2010 NaN 10 10 2011 21 21 21 2012 NaN 20 20 2013 10 10 10 2014 NaN NaN NaN 2015 30 30 NaN 2016 31 NaN 31 2017 45 45 45 2018 23 23 23 2019 56 56 56 After filling category1:
category1 category2 category3 year 2010 10 10 10 2011 21 21 21 2012 20 20 20 2013 10 10 10 2014 NaN NaN NaN 2015 30 30 NaN 2016 31 NaN 31 2017 45 45 45 2018 23 23 23 2019 56 56 56