Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error 'ValueError: Length of values (1) does not match length of index (54)' using pandas pd.to_numeric

I have the below dataframe:

                                          Financial KPI        Year                Value
0                                         Total Revenue         TTM             92478000
1                                         Total Revenue  12/31/2021             89113000
2                                         Total Revenue  12/31/2020             85528000
3                                         Total Revenue  12/31/2019             91244000
4                                         Total Revenue  12/31/2018             91247000
5   Net Income from Continuing & Discontinued Operation         TTM             27409000
6   Net Income from Continuing & Discontinued Operation  12/31/2021             31978000
7   Net Income from Continuing & Discontinued Operation  12/31/2020             17894000
8   Net Income from Continuing & Discontinued Operation  12/31/2019             27430000
9   Net Income from Continuing & Discontinued Operation  12/31/2018             28147000
10                                    Normalized Income         TTM             27409000
11                                    Normalized Income  12/31/2021             31978000
12                                    Normalized Income  12/31/2020             17894000
13                                    Normalized Income  12/31/2019             27430000
14                                    Normalized Income  12/31/2018             28147000
15                                            Basic EPS         TTM                     
16                                            Basic EPS  12/31/2021                 3.60
17                                            Basic EPS  12/31/2020                 1.88
18                                            Basic EPS  12/31/2019                 2.77
19                                            Basic EPS  12/31/2018                 2.64
20                                    Net_Profit_Margin         TTM   0.2963840048443954
21                                    Net_Profit_Margin  12/31/2021  0.35884775509746053
22                                    Net_Profit_Margin  12/31/2020  0.20921803386025628
23                                    Net_Profit_Margin  12/31/2019   0.3006225066853711
24                                    Net_Profit_Margin  12/31/2018  0.30847041546571397
25                                    Price To Earnings         TTM                9.125
26                                         Total Assets         TTM                     
27                                         Total Assets  12/31/2021           3169495000
28                                         Total Assets  12/31/2020           2819627000
29                                         Total Assets  12/31/2019           2434079000
30                                         Total Assets  12/31/2018           2354507000
31              Total Liabilities Net Minority Interest         TTM                     
32              Total Liabilities Net Minority Interest  12/31/2021           2899429000
33              Total Liabilities Net Minority Interest  12/31/2020           2546703000
34              Total Liabilities Net Minority Interest  12/31/2019           2169269000
35              Total Liabilities Net Minority Interest  12/31/2018           2089182000
36                 Total Equity Gross Minority Interest         TTM                     
37                 Total Equity Gross Minority Interest  12/31/2021            270066000
38                 Total Equity Gross Minority Interest  12/31/2020            272924000
39                 Total Equity Gross Minority Interest  12/31/2019            264810000
40                 Total Equity Gross Minority Interest  12/31/2018            265325000
41                                           Total Debt         TTM                     
42                                           Total Debt  12/31/2021            303870000
43                                           Total Debt  12/31/2020            282255000
44                                           Total Debt  12/31/2019            265060000
45                                           Total Debt  12/31/2018            249529000
46                   Current_Ratio (assets/liabilities)  12/31/2021    1.093144546736616
47                   Current_Ratio (assets/liabilities)  12/31/2020   1.1071675809860828
48                   Current_Ratio (assets/liabilities)  12/31/2019   1.1220733804797838
49                   Current_Ratio (assets/liabilities)  12/31/2018    1.126999466776949
50                                 Debt_to_Assets_Ratio  12/31/2021  0.09587331735812803
51                                 Debt_to_Assets_Ratio  12/31/2020  0.10010366619414554
52                                 Debt_to_Assets_Ratio  12/31/2019  0.10889539739671555
53                                 Debt_to_Assets_Ratio  12/31/2018  0.10597929842637971

I’m trying to convert the values of column ‘Value’ from string to the float type with the following line:

df_global['Value'] = pd.to_numeric(['Value'], errors='coerce')

However, with this line, I’m getting the error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ValueError: Length of values (1) does not match length of index (54)

Not sure why this is happening. To my understanding the to_numeric function should just convert all the values of that column to float. The index, without the column headers, go from 0 to 53 so why is it complaining? How can I prevent this.
Any help?

>Solution :

There is a problem with the way you are passing the column name to the to_numeric() function. You should pass the name of the column as a string, without using square brackets:

df_global['Value'] = pd.to_numeric(df_global['Value'], errors='coerce')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading