Skip to content
Advertisement

Find Word in a csv file and implement it using loops

I am having a dataframe named df which is having two columns,

JavaScript

Now what i am trying to implement is I am trying to find out company name where “gc” word exists and store it into new dataframe df1.

JavaScript

but this code is showing error

JavaScript

Advertisement

Answer

The error you’re getting is because df[‘Company name’] is not iterable, you cannot index it. What you can do is:

JavaScript

Here you loop over your dataframe df, check whether column Company name contains ‘gc’, and if so: append to new_df. Result:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement