I am trying to match parts of string from bad_boy
to good_boy
and create a column in the original df (bad_boy
) called the Right Address
but having hard time getting this accomplished. I have looked at the links below:
Replace whole string if it contains substring in pandas
Return DataFrame item using partial string match on rows pandas python
import pandas as pd
bad_boy = pd.read_excel('C:/Users/Programming/.xlsx')
df = pd.DataFrame(bad_boy)
print (df['Address'].head(3))
0 1234 Stack Overflow
1 7458 Python
2 8745 Pandas
good_boy = pd.read_excel('C:/Users/Programming/.xlsx')
df2 = pd.DataFrame(good_boy)
print (df2['Address'].head(10))
0 5896 Java Road
1 1234 Stack Overflow Way
2 7459 Ruby Drive
3 4517 Numpy Creek Way
4 1642 Scipy Trail
5 7458 Python Avenue
6 8745 Pandas Lane
7 9658 Excel Road
8 7255 Html Drive
9 7459 Selenium Creek Way
I tried this:
df['Right Address'] = df.loc[df['Address'].str.contains('Address', case = False, na = False, regex = False), df2['Address']]
but this throws out an error:
'None of [0.....all addresses\nName: Address, dtype: object] are in the [columns]'
Result being requested:
print (df['Right Address'].head(3))
0 1234 Stack Overflow Way
1 7458 Python Avenue
2 8745 Pandas Lane