python - 在 pandas python 列中追加循环输出
问题描述
我正在使用下面的代码将输出附加到空数据帧
image_data = pd.DataFrame()
for i in words:
y = re.findall('{} ([^ ]*)'.format(re.escape(i)), data)
x = y
image_data = image_data.append(x, ignore_index = True)
我得到如下输出,但我想要
0
0 30708
1 15
2 1800
0 19200
1 50
2 1180
我想要的输出是什么
0 1 2
0 30708 15 1800
1 19200 50 1180
每次循环重复时,我怎样才能使 3 行到 3 列。
解决方案
如果x
是值列表,请使用:
image_data = image_data.append([x], ignore_index = True)
将所有值追加为新行,而不是将单个元素追加为行。在此处查看有关 append 方法的更多详细信息。
推荐阅读
- sql - Azure SQL 数据库查询性能下降(查询存储的原因?)
- python - 在 Scipy Optimize Minimize() SLSQP 中共享目标和约束计算
- python - Chromedriver 不适用于硒
- c++ - 有没有办法在没有 Visual Studio 的情况下使用 DirectXTex?
- flutter - 在颤振加载中加载更多列表,但用户界面没有改变
- pandas - 如何在熊猫中通过 multiIndex 和前一个值交替值?
- python - 在 pyproject.toml 中指定命令行脚本
- reactjs - 动作创建者中的 getState 函数调用始终返回空数组
- r - 基于分布的数据帧样本
- google-api - 使用 Youtube Data API 将视频上传到 youtube 时达到每日限制