I have the following dataframe with two columns:
data = [['A', '3ykf'], ['A', '3ykf'], ['A', ], ['B', ], ['B', '6jbk'], ['B', ], ['B', ], ['C', ], ['C', ]]
df = pd.DataFrame(data, columns=['column1', 'column2'])
column1 | column2
A "3ykf"
A
A "3ykf"
B
B
B "6jbk"
B
C
C
I want to "fill up" the second column like this:
column1 | column2
A "3ykf"
A "3ykf"
A "3ykf"
B "6jbk"
B "6jbk"
B "6jbk"
B "6jbk"
C
C
Column1 is the column I want to group by, and within each group, column2 contains either a string that doesn't change within one group or it's empty.
I want to fill up the empty cells in column2 by adding the same string to each cell within one group.
The issue is that the string is not necessarily the most common value within one group, as the most common value might be an empty cell (like for group B).
Obviously, for group C, column2 can't be filled up with anything, so it should be kept empty in the resulting dataframe.
You can fill with the first avaiable value:
Result: