1

Consider:

House_prices = [10050, 42300, 50206, 105000, 22350]
Num_rooms = [4, 5, 6, 10, 12, 2]**

This is the code that I have tried:

x = df.House_prices
y = df.Num_rooms
plt.scatter(x,y)
plt.show()

I want to plot both House_prices and Num_rooms into a scatter plot.

But I got the error:

'list' object has no attribute 'House_prices'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

3 Answers3

0

You assign House_prices to df. House_prices is a list and list does not have a drop attribute.

Tom Ron
  • 5,906
  • 3
  • 22
  • 38
0

A list is not a DataFrame: you must explicitely build the DataFrame:

df = pd.DataFrame(House_prices, columns=['House_prices'])

From that point, you will be able to use all dataframes methods on df including dropna

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • df = pd.DataFrame(House_prices, columns=['House_prices']) df.dropna(axis=0, how='all', inplace=True) print('Total number of data points in House_prices = ',np.count_nonzero(~np.isnan(House_prices))) print(House_prices) –  Apr 01 '20 at 14:32
  • I have tried it –  Apr 01 '20 at 14:33
  • Total number of data points in House_prices = 5 [10050, 42300, 50206, nan, 105000, nan, 22350] –  Apr 01 '20 at 14:33
  • but there is still "nan" inside and i dont know how to remove it –  Apr 01 '20 at 14:33
  • @Samuel: In my tests, `dropna` removed the nan... Maybe you should ask a new question (editing this one will make all the answers incorrect) with the new details. – Serge Ballesta Apr 01 '20 at 14:41
0

Here house_prices is a list and lists doesn't have drop features.

In order to remove the np.nan values from a list, you may use the below logic:

New_list = [x for x in house_prices if x != "Np.nan"]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131