用熊猫中的NaN除以另一列

时间:2019-12-29 13:32:35

标签: pandas

我是python的新手。

我有一个如下所示的数据框。

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

从上面我想在DF下面做准备。

预期输出:

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

我尝试了以下代码

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

我得到了如下所示的完整NaN

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

错误是:

/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.

0 个答案:

没有答案