1

I have a huge csv file and i want to filter out the dataframes with a specific value.

dataf = pd.read_csv('table.txt', sep=',')
dataf[(dataf.Subject_code == '100')]
#print (dataf[(dataf.Subject_code =='100')])

It returns an empty data frame. I get only the headers of the file. I need all the dataframes whose subject code is equal to 100.

Student Subject_code Score 1 100 A 10 500 B 12 100 A 15 100 C

4
  • 2
    This question seems malformed. Commented Jun 18, 2020 at 17:15
  • 2
    Is there some sample data we can look at? Please look at stackoverflow.com/questions/20109391/… Commented Jun 18, 2020 at 17:18
  • are you sure it's a string column ? try dataf[(dataf.Subject_code == 100)] Commented Jun 18, 2020 at 17:19
  • Sorry, Im having a hard time posting the entire question. Commented Jun 18, 2020 at 17:23

2 Answers 2

1

Pandas most likely converts strings representing numbers to numbers (you can find out by doing dataf.info() and see if the column is numeric or Object. If it does, you should do equality check against 100 not "100".

Sign up to request clarification or add additional context in comments.

1 Comment

oh. okay. makes sense
0

Use this:

print(dataf[dataf.Subject_code == 100])

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.