I have a dataframe:
import pandas as pd
data = {'fruit': ['pear','pear','banana', 'pear', 'pear','apple', 'apple', 'cherry','cherry'],
        'fruit_type': ['unknown','pear','unknown', 'unknown', 'pear','unknown', 'apple', 'cherry','unknown'],
'country': ['unknown','usa', 'unknown', 'unknown','ghana','unknown', 'russia', 'albania','unknown'],
'id': ['011','011','011', '011', '011','011', '011', '6','6'],
'month': ['unknown','march', 'unknown', 'unknown', 'january','unknown', 'march', 'january','unknown']       
}
df = pd.DataFrame(data, columns = ['fruit','fruit_type','country', 'id', 'month'])
I want to fill rows where is unknown with value from another row for each group by id:
If we have an unknown value in the month column in the first place in the group by id we need to insert unknown values from the next row
If an unknown value in the month column not in the first place in the group by id we need to insert unknown values from the previous row
Can anyone see the problem?
Output dataframe:



