Lesson 2- Exercise on os and filesytem

Hello Schorlars! Kindly help me out on this. I want to add emi to the data but I got errors. Have tried the following codes:error 1 error 2

I am trying to do the exercise in lesson 2 of python os and filesystem.
Thanks in anticipation. I have been able to create function and get a columnar dictionary below:
loan_1 result

Use print statements in the for loop to debug your code, print "loan" and see what value it has. Variable loan is just a string representing a key of the loans dictionary.

1 Like

Yes, i have done that and it retuned the keys. I tried to modify it by using for loan in loans.values() but still get same error

have you solved your problem yet?

Yes, but I’m not satisfied with the way I did it. I would appreciate if I can get a better way to solve it, if possible.

I created another csv function which read the data in dict format of like the example. Something like this: {[a:1,b:2],[a:3,b:4]} and not in columnar format, then I apply the function of emis to the new function, and append only the emis column to the columnar dict.

I believe this is not professional, though, I was able to arrive at the solution.

1 Like

In case you want to to store data in columnar dictionary like above “loans_1”. Just remove for loop, this mean that you need to modify “loan_emi” function to take array as parameter. Another the way to solve is modify for loop to “for index in len(loans[‘amount’])” and use loans[‘amount’][index], loans[‘duration’][index],…

Okay, thank you very much for this. I will try it and get back to you on the result.

1 Like

Have tried this but I still got an error message for the for loop. for index in len(loan[‘amount’]) returns an error message. And I don’t really understand how to make the emi function parameter array.

I mean “for index in len(loans[‘amount’])” not “loan”. Because parameter “loans” you passing in function “compute_emi” is a dictionary, therefore len(loans[‘amount’]) you you length of array [100000, 200000, 628400,…] which is 9. Basically, in for loop, you go through: loans[‘amount’][0]=100000, loans[‘duration’][0]=36, loans[‘rate’][0]=0.08, loans[‘down_payment’][0]=20000,… to loans[‘amount’][8]=423000,…

Okay. Thank you for the response.

Please I’m stuck somewhere else too. I want to add a column to a data frame using a categorical variable. How can I do this?
One of the exercise in the last lesson whereby we were asked to add a col of age group. I tried doing this but the process is too long. I would appreciate if I can get a more professional way.

What I did was:
I sorted the dataset by Age col and used a new index, then created a new col with none value, then, I started changing the value using .loc of the index range. This is a long process cus I have to check the index range of each age category before imputing the value to the new col.

I not take part in this course, so I not quite understand about exercise. In case you want to change numerical column to categorical, you can use pandas.cut

1 Like

Okay, thank you very much for your help through the course. Please kindly go through my project. I would appreciate your comments. This is the link to the project fasasiganiyat95/customer-personality-analysis - Jovian. I did analysis on customer personality.

Thank you in anticipation.