excel-formula - 从单元格中提取特定的文本字符串
问题描述
请看下面的文字:
Mr. Manimaran R MMTFD NL20824448862,Room no-206
我有大约一百万个这样的单元格,我想使用公式从该文本中提取 ID 号。我面临的问题是一些 id 以 NL 开头,一些以 NH 开头,一些以 IN/IWA 开头,并且包含 id 的文本字符串的长度也不同(13/14/15 等)。有什么公式可以让我提取这些id吗?
目前我正在使用这个公式 =MID(text,FIND("NH",text,1),15)。但是我每次都需要为 NL/IN 以及 14/15 等更改它。
解决方案
您可以使用带有 python3 的 pandas 轻松快速地完成此类任务。
在 python3 外壳中
import pandas as pd
df= pd.read_excel('./your_excel_file.xlsx') ##import from excel
df['ID']=df['Data_header_name'].str.split(' ',expand=True)[4].str.split(',',expand=True)[0] ##here you can use any relevant filters to get what you want
df.to_excel('output_excel.xlsx') ## save to excel
您还需要使用 pip 安装 openpyxl、xlrd、numpy、pandas
pip install openpyxl xlrd numpy pandas
推荐阅读
- javascript - Puppeteer 键入触发 aws lambda 中的错误
- c++ - C++ windows socket UDP丢包
- java - 将字符串变量存储到字符串数组
- java - 将字符串列表转换为逗号分隔的字符串而不重复
- ios - 沙盒 Xcode 问题
- r - 如何使用 R 包“gtsummary”在汇总表中生成效果大小 [90%CI]?
- python-3.x - Pandas:如何按范围包含聚合?
- r - 如何绘制一个堆叠的条形图,其中三个分类变量表示 r 中每个方面仅其中一个的比例?
- swift - awk 命令中的多个条件 + 正则表达式
- python - 如何从不包括一个变量的字符串列表中创建新的字符串列表?