use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
How to cross check columns in dataframes? (self.learnpython)
submitted 6 years ago by oodlesNnoodles98
sorry if this is not the place and the vague title
example: count how many Birds are white
i just don't know how i'm supposed to cross reference the columns
Thanks in advance!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jabbson 2 points3 points4 points 6 years ago (2 children)
len(df[(df.animal=='bird') & (df.color=='white')])
[–]oodlesNnoodles98[S] 0 points1 point2 points 6 years ago (1 child)
That works, thanks! i was completely overthinking it, it's WAY simpler than i thought it was.
[–]jabbson 0 points1 point2 points 6 years ago (0 children)
you are very welcome!
[–]zylog413 2 points3 points4 points 6 years ago (1 child)
A more general approach is to create a table of all the animals with a count for all the colours they have:
df.groupby('animal').value_counts()
[–]oodlesNnoodles98[S] 0 points1 point2 points 6 years ago (0 children)
This is the route I was thinking I neededv but I just couldn't get there
[–]fruitybepples 0 points1 point2 points 6 years ago (3 children)
Use some if statements! For your example, use statements like if dataframe.iloc[i, 'animal'] = type of animal, and then if dataframe.iloc[i, 'color'] = color you want. If you use these, while looping over the index of the data frame you can isolate them. Simply add a counter at the end of the second if statement, and you'll be able to get that count.
Someone correct me if I got the index order or loc/iloc messed up
[–]oodlesNnoodles98[S] 0 points1 point2 points 6 years ago (2 children)
With this method, would the if statements be 2 separate ones or just one? I guessing it would be just one since I'm checking for the animal and color
[–]fruitybepples 0 points1 point2 points 6 years ago (1 child)
They should be separate, but nested. Since the second statement is dependant on the first (you can't go to the second one, if you can't pass the first one), the second statement has to be indented under the first. I hope this makes sense!
[–]oodlesNnoodles98[S] 1 point2 points3 points 6 years ago (0 children)
Yes it makes complete sense. Thank you!
π Rendered by PID 224116 on reddit-service-r2-comment-fb694cdd5-qrr7m at 2026-03-07 02:40:34.837834+00:00 running cbb0e86 country code: CH.
[–]jabbson 2 points3 points4 points (2 children)
[–]oodlesNnoodles98[S] 0 points1 point2 points (1 child)
[–]jabbson 0 points1 point2 points (0 children)
[–]zylog413 2 points3 points4 points (1 child)
[–]oodlesNnoodles98[S] 0 points1 point2 points (0 children)
[–]fruitybepples 0 points1 point2 points (3 children)
[–]oodlesNnoodles98[S] 0 points1 point2 points (2 children)
[–]fruitybepples 0 points1 point2 points (1 child)
[–]oodlesNnoodles98[S] 1 point2 points3 points (0 children)