Reputation: 153
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)
Upvotes: 0
Views: 99
Reputation: 862661
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]
Upvotes: 2