Groupby and drop NaN rows while preserving one in Pandas
问题 Given a test dataset as follows: id city name 0 1 bj NaN 1 2 bj jack 2 3 bj NaN 3 4 bj jim 4 5 sh NaN 5 6 sh NaN 6 7 sh steve 7 8 sh fiona 8 9 sh NaN How could I groupby city and drop NaN rows for name while preserving one only for each group ? Many thanks. The expected result will like this: id city name 0 1 bj NaN 1 2 bj jack 2 4 bj jim 3 5 sh NaN 4 7 sh steve 5 8 sh fiona New dataset read by df = pd.read_clipboard(na_filter = False) from excel file, please note N/A should not be considered