Python Forum

Full Version: Python Beginner
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I am new to programming and python. I am currently taking a course and I have a data analysis assignment where I am analysing property price data over a number of years and regions. I have imported a csv file and created a list of regions and a second list with prices.Following as shortened example:

region = [London, Glasgow, Liverpool, London, Liverpool, Manchester, Cardiff, Liverpool, London, Glasgow, Liverpool]

price = [550000,350000,402000,750000,600000,230000,987000,236000,578000,643000,867000]

I have calculated and displayed the basic stats (Mean, Median, Max, Min, Std dev) on the price list as a whole and everything works good.

Now I would now like to count and display the number of properties sold by region and then provide the basic stats by region. In other words I want to create a price list for each unique region. This is where i am really struggling in how to accomplish this.

Any ideas/suggestions and code example of how to approac this.

I am not allowed use pandas numpy etc.
First, make sure your code for generating the statistics is in a function. You want to be able to pass different data sets to the function to calculate the stats for the different regions.

Then you want to make subsets of the data for each region and pass them to the function. I would make a dictionary, where the keys are the region names. Then loop through the observations in the data, assigning each one to the correct region name in the dictionary. Once they're all in, run each one through your data function, and you're good.