Pandas日常操作5个小技巧

张开发
2026/4/4 1:55:30 15 分钟阅读
Pandas日常操作5个小技巧
Pandas日常操作5个小技巧1、获取当前路径的绝对路径dir_path os.path.dirname(os.path.abspath(__file__))#获取当前路径的绝对路径filedirj dir_path \\原始数据\\#获取原始数据下文件绝对路径2、设置千分位符pf[pf.columns[11:558]] pf[pf.columns[11:558]].applymap(lambdax:f{x:,})#改千分位格式,修改日期202301313、np查找字符串。np.char.find(x4[plmnIdList],x4[联通共享邻区]np.where(np.char.find(x4[plmnIdList],mnc01, mcc460)0,是,否)#判断邻区为支持联通用户4、Pandas列模糊筛选x4 x4[x4[plmnIdList].str.contains(r.*?mnc01, mcc460.*)]x4 x4[x4[plmnIdList].str.contains(r.*?mnc01, mcc460.*)]#使用正则表达式进行模糊匹配,*匹瓯,判断邻区为支持联通用户pf[nameclunm]np.where(pf[nameclunm].astype(str).str.contains(\[),pf[nameclunm].str.replace(\[.$,,regexTrue),pf[nameclunm])5、Pandas文本列联合操作p_mo_cell[eci1] p_mo_cell[eNodeB标识].astype(str) p_mo_cell[eci2] p_mo_cell[小区标识].astype(str)print(p_mo_cell.dtypes) p_mo_cell[eci] p_mo_cell[eci1].str.cat([p_mo_cell[eci2]],sep-)

更多文章