1

I need to compare 2 columns to find cells that contain the same words and create a third column with the result. [![https://i.stack.imgur.com/EhDim.jpg%5C]]

i did that but it only compares cells in the same row and I need it to look for repeated values ​​in the column .

import pandas as pd
import numpy as np
 

details = {
    'Column1': ['site.com/auto-new/car', 2, 30, 0],
    'Column2': ['site.com/auto/car', 1 , 25, 3]
}
 

df = pd.DataFrame(details)
df['NEW'] = np.where((df['Column1'].str.endswith('car')) & df['Column1'].str.contains('auto') & df['Column2'].str.endswith('car') & df['Column2'].str.contains('auto'), df['Column2'], np.nan)
print(df)

I should to convert dataframe to array like this?https://stackoverflow.com/questions/13187778/convert-pandas-dataframe-to-numpy-array I need This [![enter image description here](https://i.stack.imgur.com/oK3Zl.jpg)](https://i.stack.imgur.com/oK3Zl.jpg)

william
  • 41
  • 4
  • Can you share a reproducible example that matches the image https://i.stack.imgur.com/oK3Zl.jpg ? And also an explicit expected output (describing the third column) ? – Timeless Jan 04 '23 at 22:33
  • So the second image is how i want to organize the lines – william Jan 04 '23 at 22:54

0 Answers0