There are a few different ways that we can access the data within a DataFrame. You have the option to choose by the column or by the record. Let’s look at how to do both.
Accessing data by a column is the same as accessing data from a dictionary with the key. Within the first set of brackets, you put the column name that you would like to access. If you’d like to access a specific record within that column, you use a second set of brackets with the index:
1| # directly selecting a column in Pandas
2| print( df["ages"] )
3| print( df["ages"][3] ) # select the value of "ages" in the fourth row (0-index based)
5| # print( df[4] ) doesn't work, 4 is not a column name
Go ahead and run the cell. On line 2 we output the entire ages column of data. The second statement allows us to access the value at a specific cell. Be careful though, putting the index number in the first set of brackets will create an error, as the first set is only meant for column names and “4” is not a column.