0

I have a dataframe df

I would like to extract the the info from these two columns: 'rating' and 'bi_adv_adj' such that the output would only return the rows which bi_adv_adj is not empty and each pair of words would have their own rating. Below is the sample of the output.

output

Note that sangat cocok, kurang sesuai, begitu megah are from index 5 of the dataframe with rating 8.

Below is the code I tried but I cannot get the rating to repeat based on the len of words. Any suggestions are welcomed. Thank You!

indo = []
rating = []
for i in range(len(df)):
    if len(df['bi_adv_adj'][i]) > 0:
        for j in range(len(df['bi_adv_adj'][i])):
            indo.append(df['bi_adv_adj'][i][j])
            rating.append(df['rating'][i])
odebear
  • 19
  • 4

0 Answers0