Note
Go to the end to download the full example code.
12.3.10.4.3. Grouping data#
import pandas as pd
import numpy as np
Concat
Create a dataFrame
dataFrame = pd.DataFrame(np.random.randn(10, 4))
break in pieces
pieces = [dataFrame[:3], dataFrame[3:7], dataFrame[7:]]
pd.concat(pieces)
Join
left = pd.DataFrame({"key": ["foo", "foo"], "lval": [1, 2]})
right = pd.DataFrame({"key": ["foo", "foo"], "rval": [4, 5]})
pd.merge(left, right, on="key")
Grouping
dataFrame = pd.DataFrame(
{
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
"B": ["one", "one", "two", "three", "two", "two", "one", "three"],
"C": np.random.randn(8),
"D": np.random.randn(8),
}
)
dataFrame.groupby("A").sum()
dataFrame.groupby(["A", "B"]).sum()
Total running time of the script: (0 minutes 0.011 seconds)