-1

Press here for Dataset relating to question

How do you extract only the Male rows into another dataset whilst keeping the rownames & column names intact?

user9186277
  • 45
  • 1
  • 7
  • I gave you a downvote because there is no reproducible example data or code. In addition, it is not clear what is your desired output. If you can correct those, I will consider to retract the downvote or even give you an upvote. – www Feb 17 '18 at 20:22

1 Answers1

0

I think

mydf[mydf["sex"] == "Male"],]

has the effect you want (where mydf is the name of your dataframe). Note that mydf["sex"] is the column of values labeled "sex" and mydf["sex"] == "Male" is a column of Boolean values (TRUE where the value is "Male").

The comma with nothing between it and the right square bracket mydf[...,] is important. It means, select all columns.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48