0

I am a newbie in python.

I have a dataframe as shown below.

Price        Area
80           4
90           10
20           NaN
60           12
50           NaN

From the above I would like to prepare below DF.

Expected Output:

Price        Area    Price_Per_Unit_Area
80           4       20
90           10      9
20           NaN     NaN
60           12      5
50           NaN     NaN

I tried below code

df['Price_Per_Unit_Area'] = df['Price']/df['Area']

I got full NaN as shown below

    Price        Area    Price_Per_Unit_Area
    80           4       NaN
    90           10      NaN
    20           NaN     NaN
    60           12      Nan
    50           NaN     NaN

Error are:

/Users/d.ali/pythenvda/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """Entry point for launching an IPython kernel.
Danish
  • 2,719
  • 17
  • 32
  • `df['Price']/df['Area']` produces your expected output for me. – fsl Dec 29 '19 at 13:36
  • 4
    this means the current df is derived from another df. if there is another method which creates this df, put a `.copy()` there and it should be fixed – anky Dec 29 '19 at 13:37

0 Answers0