網站首頁 編程語言 正文
一、使用replace+空格
ordersdetaildf['商品名稱2']=ordersdetaildf['商品名稱'].apply(lambda x:x.replace(" ",""))
上述代碼表示:在Dataframe當中創建新的一列,名字叫做商品名稱2,是對商品名稱列當中的空格進行去除之后的新的數據。
對制表符和換行符等等也可以進行同樣的操作:
ordersdetaildf['商品名稱2']=ordersdetaildf['商品名稱2'].apply(lambda x:x.replace("\n","").replace("\\t\\r",""))
二、使用replace+unicode編碼
但是在某些情況下,我發現僅僅使用replace是無法去除空格的:
ordetgb=ordersdetaildf.groupby('訂單編號',as_index=False)["商品名稱"].apply(lambda x:'|'.join(x.values)).reset_index(drop=True) #替換成|很重要
當我想將相同訂單編號的商品名稱進行合并的時候,發現使用join后會出現很多空格,這是使用replace是無法去除空格
解決方法:
# 經過excel查詢code(a1) unicode=u00A0 不間斷空格
ordetgb['商品名稱']=ordetgb['商品名稱'].astype(str).apply(lambda x:x.replace(u"\u00A0",""))
原文鏈接:https://blog.csdn.net/wxfighting/article/details/125089179
相關推薦
- 2022-04-28 WPF使用Grid網格面板布局_實用技巧
- 2022-02-17 Flutter InAppWebView在showModalBottomSheet中無法滾動
- 2022-07-18 springboot解決Invalid character found in the request
- 2022-06-23 VBS?批量Ping的項目實現_vbs
- 2022-09-18 ASP.NET實現文件上傳功能_實用技巧
- 2022-04-24 Android為View添加拖放效果的方法實例_Android
- 2023-01-21 python?flask自定義404錯誤頁面方式_python
- 2022-10-04 python?Dataframe?合并與去重詳情_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支