I wanted to fill in the na values in 'Col' by the ID number. I have tried groupby
df=pd.DataFrame({
'ID':[1,2,1,2,1,2],
'Col':['One','NaN','NaN','Two','NaN','NaN']
})
This is the expected output:
df=pd.DataFrame({
'ID':[1,2,1,2,1,2],
'Col':['One','Two','One','Two','One','Two']
})
I know this is an easy example but I would appreciate any help you could give me. Also I have a dataframe with 1 million rows so anything that would be time efficient would be appreciated
What I have tried:
x=df_total[df_total['id'].astype(str)=='2']
buck_map = dict(x[~x['buckets'].isnull()][['id','buckets']].values)
x['buckets']=x['id'].map(buck_map)