I would like to know how to find the difference between the maximum and minimum values of three columns in python. (Column name: POPESTIMATE2010-POPESTIMATE2012) Then I have to find the maximum result among all my records. In other words, in which district did the largest absolute change in population occur between 2010-2012?
eg. If during the three-year period the population of the district is 100, 80, 130, then the biggest change in this period will be 130-180 | = 50.
Here is my code:
import pandas as pd
census_df = pd.read_csv('census.csv')
def answer_one():
return ((census_df['POPESTIMATE2010'],census_df ['POPESTIMATE2011'],census_df ['POPESTIMATE2012']).max()-(census_df['POPESTIMATE2010'],census_df ['POPESTIMATE2011'],census_df ['POPESTIMATE2012']).min()).max()
answer_one()
user1492588
source
share