0

I am working with some data sets here to hone my skills working with csv's. I am experiencing an issue when I go to plot the data. I am working with this dataset: Housing Dataset

I have created a variable from the dataset using a Pandas dataframe and called it: prices_based_on_beds . My goal is to create a scatter plot of the beds vs. price. Maybe then create a regression model and write a little program to predict the price based on the number of beds, and eventually also based on location (the csv file has location information as well).....

prices_based_on_beds['beds'] a dictionary, will return (sample below)

{0: 2,
 1: 3,
 2: 2,
 3: 2,
 4: 2,
 5: 3,
 6: 3, ...} 

The problem I am having lies with the index associated with the value. It shows 0: 2 which as I am sure you can see, creates a problem when trying to make a scatter plot.

How can I clean this data to remove these index values such as 0: or 6: so that when I call on prices_based_on_beds['beds'] my return is:

{2, 3, 2, 2, 2, 3, 3, ...}
Dave
  • 329
  • 1
  • 2
  • 9
  • what do you expect to see what you do: prices_based_on_beds[1]? – adhg Jan 25 '20 at 18:14
  • `prices_based_on_beds['beds'][1]` returns ` 3 ` – Dave Jan 25 '20 at 18:16
  • 2
    Have you tried: `prices_based_on_beds['beds'].values()`? – mechanical_meat Jan 25 '20 at 18:16
  • 2
    Does this answer your question? [How can I get list of values from dict?](https://stackoverflow.com/questions/16228248/how-can-i-get-list-of-values-from-dict) – Simon Crane Jan 25 '20 at 18:17
  • @bernie yes I think this is pointing me in the right direction. Thank you. – Dave Jan 25 '20 at 18:18
  • 1
    _The problem I am having lies with the index associated with the value._ Be careful. They're not indexes, they're keys. An index has a particular meaning in Pandas, so this complicates things needlessly. How did you create the DataFrame, by the way? There might be a better way which involves isolating only the values at an earlier time in the program. – AMC Jan 25 '20 at 19:27
  • @AMC I realized this at some point a couple hours ago. Rookie mistake. – Dave Jan 25 '20 at 20:59

1 Answers1

0

The answer to my question was to add .values() to my definition of the x values list and y values list. The reason I had this lapse in judgement was because I was thinking that the key I was pulling information from was simply filled with values. I didn't realize this until later on, that the key contained a dictionary of key:values.

Dave
  • 329
  • 1
  • 2
  • 9