Skip to content
Advertisement

How can I add to a dataframe count values of another?

I have a problem that I would like to solve with a dataframe. The index of this table represents a cluster. I have a dataframe called “representative points” that has this structure:

JavaScript

On the other hand I have a dataset containing a point with the cluster it belongs to. In this case the index does not mean anything important.

JavaScript

the case is that I would like to add to the dataframe “representative points” a column with the number of points that belong to the cluster. Any idea how I can do it?

Advertisement

Answer

I think that you may need something like

JavaScript

how=’outer’ means that you keep both indices from a with no counts as well as clusters from b with no corresponding index in a. If you need something else, you may need “left”, “right” or “inner”.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement