I have a pandas dataframe and want to select rows where values of a column starts with values of another column. I have tried the following:
import pandas as pd
df = pd.DataFrame({'A': ['apple', 'xyz', 'aa'],
'B': ['app', 'b', 'aa']})
df_subset = df[df['A'].str.startswith(df['B'])]
But it errors out and this solutions that I found also have not been helping.
KeyError: "None of [Float64Index([nan, nan, nan], dtype='float64')] are in the [columns]"
np.where(df['A'].str.startswith(df['B']), True, False)
from here also returns True
for all.