栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

改善Pandas DataFrame的行追加性能

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

改善Pandas DataFrame的行追加性能

我还在循环中使用了数据框的 append 函数,感到困惑的是它的运行速度如何。

根据此页面上的正确答案,为遭受苦难的人提供有用的示例。

Python版本:3

熊猫版:0.20.3

# the dictionary to pass to pandas dataframedict = {}# a counter to use to add entries to "dict"i = 0# Example data to loop and append to a dataframedata = [{"foo": "foo_val_1", "bar": "bar_val_1"},        {"foo": "foo_val_2", "bar": "bar_val_2"}]# the loopfor entry in data:    # add a dictionary entry to the final dictionary    dict[i] = {"col_1_title": entry['foo'], "col_2_title": entry['bar']}    # increment the counter    i = i + 1# create the dataframe using 'from_dict'# important to set the 'orient' parameter to "index" to make the keys as rowsdf = Dataframe.from_dict(dict, "index")

“ from_dict”函数:https
://pandas.pydata.org/pandas-
docs/stable/generation/pandas.Dataframe.from_dict.html



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/641492.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号