I have a pandas dataframe where one column has values in kiloTon as abbreviated 'kt'. Now when I perform groupby on Country column and year column and call aggregation function sum on Value column, it's not actually doing sum of values in value column.
After performing above action, following is coming:
However the expected output should be:
Also the 'Value' column is of type object.
Any help will be useful.
If you are using values with mixed numbers and letters then they will be strings of Pandas dtype object. You need to split of the numerical part, convert to an integer, put into a new column and then use groupby with sum or whatever. For example:
gives: