# Data Science - My 30 day Challenge starting on 19th Oct 23

Day 20 - 29%

I still need a lots of practice with writing code… because I am feeling I am still not well versed with syntax and all different variants available within the functions…

For example in the given problem below, it looks straight forward when you look at it but it took me almost few hours to get to the bottom of it:

The list contains strings representing the total cost in USD(\$) caused by `34` category 5 hurricanes (wind speeds ≥ 157 mph (252 km/h )) in the Atlantic region. For some of the hurricanes, damage data was not recorded (`"Damages not recorded"`), while the rest are written in the format `"Prefix-B/M"`, where `B` stands for billions (`1000000000`) and `M` stands for millions (`1000000`).

Write a function that returns a new list of updated damages where the recorded data is converted to float values and the missing data is retained as `"Damages not recorded"`.

solution:
damages = [‘Damages not recorded’, ‘100M’, ‘Damages not recorded’, ‘40M’, ‘27.9M’, ‘5M’, ‘Damages not recorded’, ‘306M’, ‘2M’, ‘65.8M’, ‘326M’, ‘60.3M’, ‘208M’, ‘1.42B’, ‘25.4M’, ‘Damages not recorded’, ‘1.54B’, ‘1.24B’, ‘7.1B’, ‘10B’, ‘26.5B’, ‘6.2B’, ‘5.37B’, ‘23.3B’, ‘1.01B’, ‘125B’, ‘12B’, ‘29.4B’, ‘1.76B’, ‘720M’, ‘15.1B’, ‘64.8B’, ‘91.6B’, ‘25.1B’]

updated_damages =

for damage in damages:
if damage is not “Damages not recorded”:
if damage.endswith(“M”):
damage = damage.replace(damage[-1],“”)
damage = float(damage) * 1000000
updated_damages.append(damage)
elif damage.endswith(“B”):
damage=damage.replace(damage[-1],“”)
damage = float(damage) * 1000000000
updated_damages.append(damage)
else:
else:
updated_damages.append(damage)
print(updated_damages)

Output:
[‘Damages not recorded’, 100000000.0, ‘Damages not recorded’, 40000000.0, 27900000.0, 5000000.0, ‘Damages not recorded’, 306000000.0, 2000000.0, 65800000.0, 326000000.0, 60300000.0, 208000000.0, 1420000000.0, 25400000.0, ‘Damages not recorded’, 1540000000.0, 1240000000.0, 7100000000.0, 10000000000.0, 26500000000.0, 6200000000.0, 5370000000.0, 23300000000.0, 1010000000.0, 125000000000.0, 12000000000.0, 29400000000.0, 1760000000.0, 720000000.0, 15100000000.0, 64800000000.0, 91600000000.0, 25100000000.0]

1 Like

Posting your progress like this is awesome!!!

1 Like

Day 21 & 22 - Again working on another project called Hurricanes…

More learning is actually happening when working on these projects…

Although, it feels like I am learning a when I was doing the small exercises based on each function (spoon feeding)… I am finding it not easy to recollect the syntaxes fast enough when doing the coding…

So, only through practicing those exercises the knowledge is getting codified into the mind…

Day 23 - My brain is a bit overwhelmed and can’t think through… had to take a break…

There are many ways to skin a cat… so it comes down to how best we are versed with the various functions available…

I am ok to think the simple logic but thinking in function creation needs a lots of practice… and def functions does make program much simpler…

I was trying to keep myself accountable… Thanks for the comment…

Day 24 - It was an off day yesterday due to familial commitments…

Day 25 - Hurricane project - converting alphanumericals to numericals using def functions

dam =
def new_damages(damages):

# Update Recorded Damages

conversion={“M”:1000000,“B”:1000000000}
for dams in damages:
if dams == “Damages not recorded”:
dam.append(dams)
elif dams[-1] == “M”:
dam.append(float(dams[:-1]) * conversion[“M”])
else:
dam.append(float(dams[:-1]) * conversion[“B”])
return dam
print(new_damages(damages))

This code actually sounds more professional because it is less lines of code to produce same results… since it is a function, you are able to call it whenever you want…

Day 26 - Still on the hurricane project… being new to coding and being in perfection syndrome actually hampering my progress… perfection is actually leading to procrastination… or is there something else going on in learning to code…

I might need to create a cheat sheet of all inbuilt functions and their proper syntaxes… may be…

Day 28 - Honestly, I am so used to looking for answers on internet, to solve problem the first thing i am doing is to search for answers… It is time consuming… the issue I am facing is not looking for answers… actually looking for a perfect answer (if there is any)… Now, how do I get my mental muscle to work on a answer myself… when I did, my answers were not as good as the best answers… like using creating functions to solve a problem…

Still work in progress…

Another way to shorten the above code…

conversion={“M”:1000000,“B”:1000000000}
for dams in damages:
if dams == “Damages not recorded”:
dam.append(dams)
elif dams[-1] in conversion.keys():
dam.append(float(dams[:-1]) * conversion[dams[-1]])
return dam
print(new_damages(damages))

Day 29 - seeing and learning is also a great way of learning… we don’t have to reinvent the wheel…

however, we need to overcome the feeling that I am not good enough because my code is long… or my logic is not as efficient as someone elses… I guess by practicing and seeing other codes, we will be able to exposure our brain to new ideas…

30% progress in 30 days is insane!!! Congratulations

1 Like

Thanks for your comment… it looks a lot of progress… because of the way Codecademy structured the course…

I have been at this level for a while because projects take a long time to get my head around the basics to get the results…

I think from here on it is not fast progress but slow and steady to gain understanding of writing solutions…

Day 30 - so I have done the 30 days challenge…

What I have learnt from this challenge is that learning basics is easy…

To learn to code, we need to spend a lot of time in practicing it… Also, it is not wrong to search and see other people’s codes to see how their logic is working… there are many ways to get to the solution… some are better than others…

Practice… practice… practice…

1 Like

Hello friend,

What you did is absolutely fascinating, I started the same path not long ago, I had taken the Learn python 3 course up to 70% and then I switched to the same path as you. Any tips ? I would like to also ask if it’s okay to keep in touch through discord. I would also love to stay updated on your progress. My Discord: a.a._52698

Hi,

Thanks for stopping by. That is awesome to hear about your progress as well.

It is nice to have another person traveling on this path and it would be great to share ideas and progress along. I don’t use discord as much although I have an account and didn’t find much response to questions.

1 Like