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?
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?
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.