Home > Blockchain >  Pandas concat only beside certain column values
Pandas concat only beside certain column values

Time:12-24

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"?

CodePudding user response:

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
  • Related