0

I have a 100 row dataframe with a column "genres" containing either "Romance" or "Fantasy". I have another dataframe with 50 values. How do I horizontally concatenate these values only beside cells containing "Romance"?

  • 1
    I'm not sure what you exactly mean at the moment, but aren't you simply searching for a merge function? – Kylian Dec 23 '21 at 14:01
  • But I don't have any identical columns. How do I merge only where a column cell contains a specific value? – LonanKeane Dec 23 '21 at 14:10
  • Could you share your data or simply take a screenshot? That might make it easier for further answers – Kylian Dec 23 '21 at 14:11
  • You can use [this](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) link as guidance on how to provide some data. – sophocles Dec 23 '21 at 14:16
  • @Kylian I'm not sure I have time for that now. Could you point out exactly what you don't understand in my question? – LonanKeane Dec 23 '21 at 14:25

1 Answers1

0

Your question is ambiguous, you should provide an example of input/output. However, if I understand correctly, you can add values only in rows matching Romance (provided there are 50 of these rows) by using loc:

df.loc[df['genres'].eq('Romance'), 'new_column'] = other_df['col'].values
mozway
  • 194,879
  • 13
  • 39
  • 75
  • I know sorry about that. Your suggestion is almost working. My other dataframe 'Ratings' contains only one column of 50 string values. It is currently displaying NaN values when joined. – LonanKeane Dec 23 '21 at 14:56
  • Use `other_df['col'].values` – mozway Dec 23 '21 at 14:59