Question:
How to search for a name in a CSV file imported as a dataframe in python?
Green_Goddess
2019-12-11 19:49:39 UTC
I have a CSV file which lists the rank, name, country, category, sales, profits, assets, and marketvalue of about 2000 companies. I have imported it as a dataframe in the following way:
import pandas as pddf = pd.read_csv('Forbes2000.csv')

Now I need to search for only the companies whose names include 'General' such as General Electric, General Motors, etc. 

What is the best way to search for a name in the 'name' column and save it to a new dataframe?
Three answers:
keerok
2019-12-12 09:04:12 UTC
If you open the original CSV file in Excel, you can use Ctrl-F to find those entries one by one. If you want to select them or put them together in consecutive lines, you can use the IF function to do so.
?
2019-12-12 00:51:13 UTC
Sort by Name column, then all the Generals should be together and you can copy and paste them elsewhere.
EddieJ
2019-12-11 20:07:13 UTC
You probably should use .split ().



You could use a dictionary to convert the words into numbers, if you have learned about those.



You would probably use if / elif to process the operator.



Try to write some code and if you have trouble, show us what you have.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...