0

I am trying to use str.match() and i did use this function with my data. and its working very well. But I have a question, I want to save the rest of the data in another DataFrame, and then save it to_csv().

Any Idea about that. Thanks in advance.

Address = df[df['Address'].str.match('nan')]
Address = pd.DataFrame(Address)
Address.to_csv(r'nan_Address_df.csv',index = False, header=True)

1 Answer 1

2

I suggest create new variable mask, filter for Address matched rows and for Address1 non matched rows with inverted mask by ~:

mask = df['Address'].str.match('nan')
#alternative
#mask = df['Address'].str.contains('nan')
Address = df[mask]

Address1 = df[~mask]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.