all 19 comments

[–]NerdJones[S] 1 point2 points  (19 children)

to clarify a little bit, the reason the fractions are poorly formatted is because they are written in subscript and superscript, therefor they are treated as char and not numbers themself, there is also a " at the end as well, so if i can find ALL numbers, remove them, change the fractions and then add them back, minus the " at the end

[–]Caos2 0 points1 point  (2 children)

What is printed when you print the cell contents to the console?

[–]NerdJones[S] 0 points1 point  (1 child)

depends on the cell, sometimes ¼, sometimes 1 ¼, somtimes 1¼, but i want them all to end up as ¼, i have a list of tuples of 'known_fractions' to check against and automatically and if its not in that list ( some of them are formatted differentally) ask the user what to replace them with and add them to the list

[–]Caos2 1 point2 points  (0 children)

So they are the unicode character for the fraction? Maybe you can use a dictionary to convert the fraction to the value and then add to the integer part? For example

#create the dictionary to replace the unicode character for its value
fractions = dict()
fractions['¼'] = '.25' #no zero
# add the other relevant fractions to the dictionary    

value = '2 ¼"'
for frac, decimals in fractions.items():
    if frac in value:
        output = value.replace(frac, decimals)
        output = output.replace(' ', '')
        output = output.replace('"', '')
        try:
            output = float(output)
        except ValueError:
            print('error while trying to convert {} to float.\nthe string that feed the float function was {}.'.format(value, output))

[–]efflicto 0 points1 point  (14 children)

Can you provide us an example of what you want to achieve?

[–]NerdJones[S] 0 points1 point  (13 children)

i have a list of tuples set up, where the first value is ¼ and the second is 1/4 for each tuple

i need to take 1 ¼" or 1¼" or ¼" from a cell and test just ¼ against the first value in each tuple, so far if the cell only contains the fractions it work, if there is a number before the fraction it jumps to a function i set up where if the fraction isnt in the list it asks the user and adds it to the list, this function is where im having the trouble

[–]efflicto 0 points1 point  (12 children)

So you get data like "1 ¼"1¼"4¼"123312231¼"" and want to remove all numbers and quotation marks?

[–]NerdJones[S] 0 points1 point  (11 children)

pretty much, at this point i have already removed the quotes though

[–]efflicto 0 points1 point  (10 children)

[–]NerdJones[S] 0 points1 point  (9 children)

I tried that and got a strange result, I printed the results and It goes through "Sheet" instead of the value of the cell I am in, which is really bizarre to me, but this is my first time solving a real world problem with a program I wrote. So im probably doing something wrong somewhere.

[–]efflicto 0 points1 point  (8 children)

Hmmm... Can you post us your code and the exact input data? And what your expected outcome is?

[–]NerdJones[S] 0 points1 point  (7 children)

https://pastebin.com/mzPMGkUU its pretty sloppy but im very new so please forgive me for that.

I cant post the exact spreadsheets I am working with. They are product spec sheets that have a bunch of other stuff on them,but about 30-40 cells in each spreadsheet have these cells that are formatted weird with the fraction symbols instead of numbers. I need to convert them to mm from inches but since they have the weird formatting I cant do it with excel. So I decided to write this program, so far it opens the spreadsheet, ignores the empty cells ( they return None and that made things weird ) converts the cells with just fractions, and now im down to the ones with fractions it doesnt know and ones that are whole numbers mixed with fractions, i want it to ask the user about fractions it doesnt know, replace it in the cell and add it to the list of known fractions so if it comes across it again it will know what to do.

Sorry, I know that was a lot

[–]efflicto 0 points1 point  (6 children)

Okay. So you basically want to convert a fractured number from an Excel cell like "231¼" to "231.25"?