3. Cleaning Data: Let s be a string that contains a sequence of decimal numbers separated by commas, but somehow the dat

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

3. Cleaning Data: Let s be a string that contains a sequence of decimal numbers separated by commas, but somehow the dat

Post by answerhappygod »

3 Cleaning Data Let S Be A String That Contains A Sequence Of Decimal Numbers Separated By Commas But Somehow The Dat 1
3 Cleaning Data Let S Be A String That Contains A Sequence Of Decimal Numbers Separated By Commas But Somehow The Dat 1 (84.98 KiB) Viewed 65 times
***USE STARTER CODE PLEASE***
3. Cleaning Data: Let s be a string that contains a sequence of decimal numbers separated by commas, but somehow the data is corrupted and a random * shows up either right after a comma, before a comma, or before the first term of an integer number. e.g. (that's exempli gratia, latin abbreviation of 'for example’) s = ‘1.23,*2.4*, 3.123,*5.1, 8.7*, *7.23, *3.23*". Write a program that prints the sum of the numbers in the string s. Note, the whitespace is unevenly distributed in the string as well. Do this 2 ways: 1. without using any built in functions or methods associated to the string object but with a for or while loop, and 2. with built in string methods.
=# # # method 1 # # # cleaning data example # # ??? indicates you will need to fill in myStr = '1.23, *2.4*, 3.123, *5.1, 8.7*, *7.23, *3.23*' # subStr = = 0 tally for s in myStr: if s == ',': print(subStr) tally += float(subStr) subStr = elif s == '*'; pass elif ??? ??? else: ??? print(subStr) tally += float(subStr) print(tally) =# = # # # method 2 myStr2 = myStr.replace('*','') print(myStr2) sSplit myStr2.split(',') rint(sSplit) # # you can now use other string methods to finish this up
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply