In [ ]:
# Make sure pandas is loaded
import pandas as pd

# read in the survey csv
surveys_df = pd.read_csv("surveys.csv")

In [ ]:
# Method 1: select a 'subset' of the data using the column name
surveys_df['species_id']

# Method 2: use the column name as an 'attribute'; gives the same output
surveys_df.species_id

In [ ]:
# creates an object, surveys_species, that only contains the `species_id` column
surveys_species = surveys_df['species_id']

In [ ]:
# select the species and plot columns from the DataFrame
#surveys_df[['species_id', 'plot_id']]

# what happens when you flip the order?
#surveys_df[['plot_id', 'species_id']]

#what happens if you ask for a column that doesn't exist?
#surveys_df['speciess']

In [ ]:
# select rows 0, 1, 2 (row 3 is not selected)
surveys_df[0:3]

In [ ]:
# select the first 5 rows (rows 0, 1, 2, 3, 4)
surveys_df[:5]

# select the last element in the list
# (the slice starts at the last element,
# and ends at the end of the list)
surveys_df[-1:]

In [ ]:
# using the 'copy() method'
true_copy_surveys_df = surveys_df.copy()

# using '=' operator
ref_surveys_df = surveys_df

In [ ]:
surveys_df = pd.read_csv("surveys.csv")

In [ ]:
# iloc[row slicing, column slicing]
surveys_df.iloc[0:3, 1:4]

In [ ]:
# select all columns for rows of index values 0 and 10
surveys_df.loc[[0, 10], :]

# what does this do?
surveys_df.loc[0, ['species_id', 'plot_id', 'weight']]

# What happens when you type the code below?
surveys_df.loc[[0, 10, 35549], :]

In [ ]:
surveys_df.iloc[2, 6]

In [ ]:
surveys_df[surveys_df.year == 2002]

In [ ]:
surveys_df[(surveys_df.year >= 1980) & (surveys_df.year <= 1985)]

In [ ]: