0

I need to convert list to float, and divide the number of the floats. It is returning this error:

   Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/user/Desktop/MESA /main.py", line 14, in <module>
    IndonesiaCompany().calculate_the_percentage_of_shareholding_of_shareholders(df)
  File "/Users/user/Desktop/MESA /clean.py", line 31, in calculate_the_percentage_of_shareholding_of_shareholders
    shareholdings_as_percentages = [round(float(shareholding) / number_of_shares_in_paid_up_capital * 100) for shareholding in shareholders_number_of_shares]
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Desktop/MESA /clean.py", line 31, in <listcomp>
    shareholdings_as_percentages = [round(float(shareholding) / number_of_shares_in_paid_up_capital * 100) for shareholding in shareholders_number_of_shares]

The codes that I have is as follows:

     def calculate_the_percentage_of_shareholding_of_shareholders(self, df):
            shareholders_number_of_shares: List = self.extract_shareholders_number_of_shares(df)
            number_of_shares_in_paid_up_capital= self.extract_paid_up_capital()
            shareholdings_as_percentages = [round(float(shareholding) / number_of_shares_in_paid_up_capital * 100) for shareholding in shareholders_number_of_shares]
    
            return shareholdings_as_percentages

Is there any method to convert the above list to float and to solve the error?

htm_01
  • 115
  • 6
  • 1
    Please post the full error, not just the location of it. – Unmitigated Feb 24 '23 at 00:44
  • Does this answer your question? [In Python, how do I convert all of the items in a list to floats?](https://stackoverflow.com/questions/1614236/in-python-how-do-i-convert-all-of-the-items-in-a-list-to-floats) – Shorn Feb 24 '23 at 00:47
  • Hi, thanks! I tried the codes as discussed, but it returned the same error. – htm_01 Feb 24 '23 at 00:49

0 Answers0