python - how to convert one string row into many columns in pandas?
问题描述
I have a data frame with shape (30420279, 1). some rows contain simple values like size = 100, others include complex values like in the following snipping:
other rows contain also other combination of values like the following snipping
as we can see now, the rows are like dictionary formate {key = value}. what I wanted to do is to extend the data frame shape from one column (30420279, 1) up to many columns depending on the keys that we have like in the snipping (size, async, batchFrequency..).
解决方案
效率不是特别高,但给定参数列表,您可以使用相应的正则表达式生成列。
params = ['async', 'size']
for p in params:
df[p] = df['long_string'].str.extract(fr'{p}=([^,]+)')
推荐阅读
- pandas - TypeError:只能将 str(不是“列表”)连接到 str - pandas
- php - 事务在插入查询中无法正常工作
- html - 我想在 Reactjs 中添加 addEventListener() 如果我点击这个模型之外,模型就会关闭
- java - 如何将随机数分配给按钮 [5][5] 的矩阵。从1到25的数字请回答
- docker - SignalR .NetCore Api 在使用 docker-compose 运行时不起作用
- java - java servlet 上的 Tomcat 404
- javascript - Promise.all() 在完成之前停止工作
- python - 如何在python中使用selenium webdriver从网页中提取Total Confirmed的信息
- php - 获取数组对象的最大值
- sql - 为什么我在插入表时收到错误 ora-00904 无效标识符?