I have a pandas dataframe with two street address columns. I would like to check the value in each column to see if it starts with a number. Then I want to create a third column that returns the field value that starts with a number.
Consider the following df:
df = pd.DataFrame({"A":["123 Fake St","456 Fake St","Crown Building","Other Building"],
"B":["Dorm","12 Dorm","34 Dorm","Other Dorm"]})
If both fields or neither field starts with a number then it should return column A. So the third column would be:
123 Fake St
456 Fake St
34 Dorm
Other Building
I tried using np.where:
df['C'] = np.where(df['A'][0].isdigit(), df['A'], df['B'])
I guess that doesn't take into account returning 'A' if neither starts with a number. The .isdigit part of the statement didn't seem to work anyway.
Thanks for any help!