从列中填写NAN值,并用另一列中的值填充值

发布于 2025-02-03 17:27:45 字数 1567 浏览 4 评论 0原文

我正在使用一个时间序列数据集,该数据集的兴趣列是“月”列(MES),年份列(ANO),最低价格(最低)和模式价格(MCOM)。

从2013年开始的几个月中,最小列中没有任何价值,在那个月中,想填充MCOM列中的值。

我使用以下行来找到没有最小值的几个月:

dfc.loc[(dfc['ano'] == 2013) & (dfc['mes'] == 1)]

时填充“ mcom”列中的值

dfc['ano'] == 2013 & dfc['mes'] == 1

基本上,我想在我该怎么做

?这就是数据框的负责人:

data    dia mes ano wday    prod    und proc    tipo    min mcom    max merc    date    julian
6   02/01/2013  2   1   2013    quarta  Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-02 12:00:00 1.416667
14  03/01/2013  3   1   2013    quinta  Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-03 12:00:00 2.416667
22  04/01/2013  4   1   2013    sexta   Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-04 12:00:00 3.416667
30  07/01/2013  7   1   2013    segunda Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-07 12:00:00 6.416667
38  08/01/2013  8   1   2013    nan Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-08 12:00:00 7.416667

“ tipo” variabl,只有“ sardinha”,变量的类型为:

dfc.dtypes
data       object
dia         int64
mes         int64
ano         int64
wday       object
prod       object
und        object
proc       object
tipo       object
min       float64
mcom      float64
max       float64
merc       object
date       object
julian    float64
dtype: object

I'm working with a time-series dataset whose my interest columns are the month column (mes), the year column (ano), the minimum prices (min) and the modal price (mcom).

some months from the year 2013 doesn't have any value in the min column, and in those months and want to fill with the values that are in the mcom column.

I used the following line to find the months where there are no min values:

dfc.loc[(dfc['ano'] == 2013) & (dfc['mes'] == 1)]

Basically, I want to fill the 'min' column with the values in the 'mcom' column when

dfc['ano'] == 2013 & dfc['mes'] == 1

how can I do it?

That's the head of the dataframe:

data    dia mes ano wday    prod    und proc    tipo    min mcom    max merc    date    julian
6   02/01/2013  2   1   2013    quarta  Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-02 12:00:00 1.416667
14  03/01/2013  3   1   2013    quinta  Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-03 12:00:00 2.416667
22  04/01/2013  4   1   2013    sexta   Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-04 12:00:00 3.416667
30  07/01/2013  7   1   2013    segunda Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-07 12:00:00 6.416667
38  08/01/2013  8   1   2013    nan Peixe de agua salgada   Kg  RS-SC   Sardinha    NaN 5.28    5.28    Est 2013-01-08 12:00:00 7.416667

The 'tipo' variabl, only has 'sardinha' and the types of the variables are:

dfc.dtypes
data       object
dia         int64
mes         int64
ano         int64
wday       object
prod       object
und        object
proc       object
tipo       object
min       float64
mcom      float64
max       float64
merc       object
date       object
julian    float64
dtype: object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2025-02-10 17:27:46
m = (dfc['ano'] == 2013) & (dfc['mes'] == 1)

dfc.loc[m, 'min'] = dfc.loc[m, 'mcom']
# or
dfc['min'] = dfc['min'].mask(m, df['mcom'])
# or
dfc['min'] = np.where(m, df['mcom'], dfc['min'])
m = (dfc['ano'] == 2013) & (dfc['mes'] == 1)

dfc.loc[m, 'min'] = dfc.loc[m, 'mcom']
# or
dfc['min'] = dfc['min'].mask(m, df['mcom'])
# or
dfc['min'] = np.where(m, df['mcom'], dfc['min'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文