Py学习  »  Python

在Python 3.10中使用concat向Pandas数据帧中的行添加字典

mattblack • 4 年前 • 2073 次点击  

更新到Python3.10后,我现在在使用frame时收到以下警告。将字典附加到数据帧。

FutureWarning: The frame.append method is deprecated and will be
removed from pandas in a future version. Use pandas.concat instead.

下面是代码。这仍然有效,尽管我想解决这个警告。

report = report.append({
                "period":period,
                "symbol":symbol,
                "start_date":start_date,
                "start_price":start_price,
                "start_market_cap":start_market_cap,
                "end_date":end_date,
                "end_price":end_price,
                "end_market_cap":end_market_cap,
                "return":return_
            },ignore_index=True)

我已将代码更新为以下内容,这引发了一个不同的警告:

report = pd.concat([report,{
                "period":period,
                "symbol":symbol,
                "start_date":start_date,
                "start_price":start_price,
                "start_market_cap":start_market_cap,
                "end_date":end_date,
                "end_price":end_price,
                "end_market_cap":end_market_cap,
                "return":return_
            }],ignore_index=True)

TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid

2个问题: 第一个警告错了吗? 实现这一目标的3.10方法是什么? 谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129582
文章 [ 1 ]  |  最新文章 4 年前