To select a subset of columns from a dataframe, you can use the indexing operator []
with the columns you want to select. There are several ways to do this:
main.py394 chars19 lines
In the first example, we select a single column 'Name' from the dataframe df. In the second example, we select two columns 'Name' and 'Age' using a list of column names. In the third example, we select rows where Gender is 'F' and all columns are returned. Finally, we use .loc
to select all rows and the columns 'Name' and 'Gender'.
gistlibby LogSnag