pandas 将单元格是列表的DataFrame拆成多列

方法:

pd.DataFrame(dfcol.values.tolist()) 将单元格元素是列表的列拆成多列

如果要与原来的其他列合并

pd.concat(pd.DataFrame(df\[col.values.tolist()), df其他列], axis=1)

示例:

points数组如下:

生成DataFrame如下

处理结果为:

解释:

1、dfcol.values.tolist() 解释,本例中 col=0。生成一个 dfcol.values numpy矩阵,让后用tolist()转化为列表。

2、pd.DataFrame(列表)创造一个.DataFrame。列表中每个元素是DataFrame的按行排列的元素,即第n个元素放在第n行的0列。由于元素是数组,数组在生成DataFrame时会自动分列。

3、如果使用 df_i.replace("NaN", "",inplace=True)替换NaN为空字符串,则又会变成列表。

相关推荐
三十岁老牛再出发3 天前
8月25-26日总结
python·pandas
观察员5 天前
用 Pandas 对抓取的电影数据进行分析
pandas
人工干智能5 天前
科普:pandas 时间偏移别名:ts.resample(“5Min“).sum()
python·pandas
benchmark_cc10 天前
批量获取量化数据时,如何设置合理的超时和重试机制?——QuantDash 高性能实战指南
开发语言·人工智能·python·pandas·量化·quantdash
2601_9669496510 天前
使用 Pandas 读取批量数据时如何避免内存溢出?QuantDash 量化数据工程师避坑指南
开发语言·python·pandas·tushare·akshare·quantdash
三十岁老牛再出发11 天前
08.18每日总结
c++·python·numpy·pandas
虎头金猫13 天前
如何在群晖NAS上通过Docker部署CloudSaver?群晖部署CloudSaver教程|聚合资源搜索并实现远程访问
运维·服务器·网络·python·docker·容器·pandas
Uncommon.15 天前
使用pandas处理csv并转为张量
pytorch·python·深度学习·pandas
STR_Liang17 天前
pandas.read_html 报错FileNotFoundError、OSError Traceback (most recent call last)
pandas
㳺三才人子18 天前
初探 Data Analysis - Matplotlib
python·plotly·pandas·matplotlib