python - Pandas Dataframe - find sums in column B across each label in column A -


We say that we have the following data:

  ... col1 col2 col3 I want to use Python Panda to find duplicate entries (in column 1) and add them on column 2 basis. .  

In Python I will do something like:

  l = [('A', 1), ('A', 2), ('B', 3 )] D: [i [0]] = i [1] and: d [i [0]] = d [i [i [i] 0]]] + I [1] print (d)  

then the result will be:

  {'A': 3, 'B': 3 }  

What is the purpose of using pandals to do the same thing?

Use:

  in [2]: import pandas In [2]: df = pandas.DataFrame ({"col1": ["a", "a", "b"], "cola 2": [1,2,3]}) [3]: df .groupby ("col1") Sum () out [3]: col2 in Col1 a 3 b 3 [4]: ​​df .groupby ("col1"). Sum () Reset_index () Out [4]: ​​col1 col2 one 3 1b3 [2 row x 2 column]  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -