python - 如何解决 ValueError:使用 re.findall 提取信息时,值的长度与索引的长度不匹配
问题描述
我正在尝试使用 re.findall 从很长的字符串中提取一些信息。但是我遇到了 ValueError:值的长度与索引的长度不匹配。我不确定我必须纠正什么才能使此声明生效。感谢是否有人可以给我一些指导。
df['Part Number']=re.findall(r"^\D{3}\d{4}\D{2}\d{2}\w",str(df["Path"]))
字符串示例如下:
V:\DB\CAPGrind\BEFORE\8_INCHES\WG11_5950302.1_5950302.1_A_314696_SAVE_2019_12_02.csv
path=r'V:\DB\CAPGrind\BEFORE\8_INCHES'
files=glob.glob(path+"/*.csv")
df=None
for i, f in enumerate (files) :
if i==0:
df= np.transpose(pd.read_csv(f,delimiter="|",index_col=False))
df['Path'] =f
df['Machine No']=re.findall("WG-11",str(df["Path"]))
df['Process']= re.findall("CAPGrind",str(df["Path"]))
# Not Working. Will return ValueError: Length of values does not match length of index when running. The regular expression should be correct.
df['Part Number']=re.findall(r'"^\D{3}\d{4}\D{2}\d{2}\w",str(df["Path"]))
解决方案
推荐阅读
- docker - Docker Swarm,多个主机不在同一个本地网络中,但可通过 IP 访问
- rest - curl no URL specified 错误,即使正在指定 URL
- angular - ... 在对象数组之前的目的是什么
- python - 在 python 中更改字典并创建一个新字典
- c# - 3D 点和向量 - 为什么我没有 System.Windows.Media.Media3D,我应该使用它吗?
- python - 如何对已在函数中完成的变量进行更改会全局影响变量python
- python - 在 3d 空间中为 python numpy.ndarray 找到最近的邻居
- c# - 如何在程序生成的地牢中修复 AI 的寻路问题?
- c# - UWP 动画重置为 From 状态
- r - 使用 rpivotTable 部署闪亮的应用程序时出错