List Comprehensions

As a loop

# Create a variablenext_year=[]# For each row in df.years,forrowindf['year']:# Add 1 to the row and append it to next_yearnext_year.append(row+1)# Create df.next_yeardf['next_year']=next_year# View the dataframedf

name

reports

year

next_year

Cochice

Jason

4

2012

2013

Pima

Molly

24

2012

2013

Santa Cruz

Tina

31

2013

2014

Maricopa

Jake

2

2014

2015

Yuma

Amy

3

2014

2015

As list comprehension

# Subtract 1 from row, for each row in df.yeardf['previous_year']=[row-1forrowindf['year']]