pandas中去除指定字符的实例
作者:Pywin 时间:2023-11-29 22:41:35
例表:
假如想要去掉表中的‘#',‘;'而且以‘#'和‘;'为分割线切割数据:
#将dfxA_2的每一个分隔符之间的数据提出来
col1=dfxA_2['travel_seq'].str.split('#').str[0]
col2=dfxA_2['travel_seq'].str.split('#').str[1]
col3=dfxA_2['travel_seq'].str.split('#').str[2].str.split(';').str[0]
这里只是部分代码,实际情况按需求可以灵活变化。
#建立表
DF1=pd.DataFrame({'link_id1':col1,'time_slot1':col2,'time1':col3,'link_id2':col4,'time_slot2':col5,'time2':col6,'link_id3':col7,'time_slot3':col8,'time3':col9,'link_id4':col10,'time_slot4':col11,'time4':col12,'link_id5':col13,'time_slot5':col14,'time5':col15,'link_id6':col16,'time_slot6':col17,'time6':col18,'all_time':col19})
#重新排列index的值
DF2=DF1.reset_index(drop=True)
#按照指定的列排序columns
DF=DF2.reindex(columns=['link_id1','time_slot1','time1','link_id2','time_slot2','time2','link_id3','time_slot3','time3','link_id4','time_slot4','time4','link_id5','time_slot5','time5','link_id6','time_slot6','time6','all_time'])
#保存成csv格式的文档
DF.to_csv('A_2.csv')
结果:
来源:https://blog.csdn.net/qq_36076233/article/details/64124577
标签:pandas,去除,字符
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server应用程序的高级Sql注入
2009-04-11 16:54:00
Python字符串的索引与切片
2021-08-17 23:46:00
python 包之 multiprocessing 多进程
2021-02-25 12:13:15
VS2013连接MySQL5.6成功案例一枚
2024-01-20 17:36:51
![](https://img.aspxhome.com/file/2023/3/78063_0s.jpg)
5个款MySQL常用维护管理工具
2010-10-25 19:45:00
![](https://img.aspxhome.com/file/UploadPic/201010/25/20101025203549207s.jpg)
pandas DataFrame 赋值的注意事项说明(index)
2023-03-08 06:42:58
sqlserver 动态创建临时表的语句分享
2024-01-17 23:57:45
解决mysql安装时出现error Nr.1045问题的方法
2024-01-18 11:34:30
![](https://img.aspxhome.com/file/2023/2/118212_0s.jpg)
python中的tcp示例详解
2021-06-21 21:09:46
![](https://img.aspxhome.com/file/2023/4/98894_0s.png)
pycharm下pyqt4安装及环境配置的教程
2021-11-01 16:03:57
![](https://img.aspxhome.com/file/2023/3/135393_0s.png)
python爬取淘宝商品详情页数据
2021-05-28 14:38:08
![](https://img.aspxhome.com/file/2023/0/75240_0s.png)
python机器学习案例教程——K最近邻算法的实现
2021-12-01 14:36:51
ASP充分利用Err.Description
2009-06-24 11:12:00
Python常用时间操作总结【取得当前时间、时间函数、应用等】
2021-01-12 20:32:33
vue3 setup语法糖之组件传参(defineProps、defineEmits、defineExpose)示例详解
2024-04-27 16:01:39
PHP删除数组中空值的方法介绍
2023-11-24 03:04:19
python怎样判断一个数值(字符串)为整数
2021-07-13 21:17:57
Git配置用户签名方式及原因说明
2022-06-17 05:54:50
可能是史上最细的python中import详解
2023-01-07 18:40:07
pytorch 实现tensor与numpy数组转换
2022-02-07 16:06:44