比较Regex输入和Excel电子表格,并打印/突出显示差异
因此,我正在尝试创建一个程序来执行以下操作:
- 允许用户手动输入某些字母数字字符,其中包含一些正则表达式 - 例如^masdjoeufj0。|^waoifuwh2iw9。|^abcd130。
- 删除所有正则字符/定界符 - 。|^
- 将新的字母数字字符串打印出来 - 例如Masdjoeufj0 waoifuwh2iw9 abcd130
- 将Excel电子表格的内容加载到内存中,以进行比较,
- 以比较Alphanumeric String(在步骤3中)与Excel的内容进行比较电子表格
- 区别
打印/仅突出显示我对Python的新 到目前为止已经完成:
import re
import pandas as pd
str = input("Enter Regex : ")
pattern = r"['^\', '\\.|']"
str = re.sub(pattern, " ", str)
#str = str.split()
print (str, "\n", "\n")
df = pd.read_excel (r"C:\Users\...\...\...\Spreadsheet_Comparison.xlsx")
#print (df, "\n", "\n")
我不确定到目前为止我是否已经使用了正确的方法,因此在此要感谢任何帮助/指导。
我知道这可能不是编写此程序的最专业的方式,但我不需要它,我只需要一些基本的东西来完成这项工作,这很容易且直接遵循。
事先感谢您的所有帮助。
So I am trying to create a program to do the following:
- Allow a user to manually input some alphanumeric characters, with some regex included - e.g. ^MASDJOEUFJ0.|^WAOIFUWH2IW9.|^abcd130.
- Remove all regex characters/delimiters - ,.|^
- Print out the new alphanumeric string - e.g. MASDJOEUFJ0 WAOIFUWH2IW9 abcd130
- Load the contents of an Excel spreadsheet into memory, for comparison purposes
- Compare the alphanumeric string (in step 3) against the contents of the Excel spreadsheet
- Print/highlight only the differences
I am new to Python but using my previous programming experience I have created a program which will do up to step 4 but I am having issues trying to work out the last 2 steps - here is what I've done so far:
import re
import pandas as pd
str = input("Enter Regex : ")
pattern = r"['^\', '\\.|']"
str = re.sub(pattern, " ", str)
#str = str.split()
print (str, "\n", "\n")
df = pd.read_excel (r"C:\Users\...\...\...\Spreadsheet_Comparison.xlsx")
#print (df, "\n", "\n")
I am not sure if I have even used the correct approach so far or not, so any help/guidance here is appreciated.
I am aware that this might not be the most professional way of writing this program but I don't need it to be, I just need something basic that will do the job, and that is easy and straightforward to follow.
Thanks in advance for all the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论