【发布时间】:2022-11-16 03:13:31
【问题描述】:
我正在尝试将字典添加到现有的熊猫数据框中 这就是代码的样子
features_dict = {"feature1":0,"feature2":0, ......, "featureN":1}
feature_df = feature_df.assign(**features_dict)
现在,字典中的键数超过了 100 个,需要将它们全部添加为一列。 当我运行此代码时,我收到以下警告
PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead
什么应该是更好的方法来做到这一点?
【问题讨论】: