0

So I am trying to create a program to do the following:

  1. Allow a user to manually input some alphanumeric characters, with some regex included - e.g. ^MASDJOEUFJ0.|^WAOIFUWH2IW9.|^abcd130.
  2. Remove all regex characters/delimiters - ,.|^
  3. Print out the new alphanumeric string - e.g. MASDJOEUFJ0 WAOIFUWH2IW9 abcd130
  4. Load the contents of an Excel spreadsheet into memory, for comparison purposes
  5. Compare the alphanumeric string (in step 3) against the contents of the Excel spreadsheet
  6. 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.

Suleman
  • 1
  • 1
  • your regex should look like this `f"[\^.|,]"`, and you need to avoid using the `str` as a variable name because it is a reserved word (data type) - I don't know the right world – Hanna Jun 10 '22 at 16:06
  • I'm not sure what do you mean by highlight the differences, since it seems the user can input anything. So, it's likely that there are going to be always differences. Even if the input were equal to one cell in your spreadsheet, it would be different to the others. An example of how your DataFrame looks like, and specially one your desired output would help a lot. – Ignatius Reilly Jun 10 '22 at 16:27
  • Pleas, take a look at https://stackoverflow.com/questions/30944577/check-if-string-is-in-a-pandas-dataframe, https://stackoverflow.com/questions/56170164/check-if-string-in-list-of-strings-is-in-pandas-dataframe-column, and https://stackoverflow.com/questions/17972938/check-if-a-string-in-a-pandas-dataframe-column-is-in-a-list-of-strings. – Ignatius Reilly Jun 10 '22 at 16:47
  • And also, for the last point, take a look at https://stackoverflow.com/questions/72522475/python-validate-county-state/72523153#72523153. – Ignatius Reilly Jun 10 '22 at 17:15

0 Answers0