So imagine I have data like this:
name time
0 A 1
1 A 2
2 B 3
3 A 6
4 A 7
5 A 3
6 B 1
7 B 4
Each entry has a named category and some other information. In the example above lets take time. Its the only one i care about.
I would like to produce a table which has just the individual unique name categopries and the max of each. I can do something like this:
max_table = pd.DataFrame(
{
"name": data.name.unique(),
"max_val": [
data[data["name"] == name].time.max() for name in data.name.unique()
],
}
)
But this does not feel very pandas-y. I have to go to and from the pandas table between lists and do some array expansion to make this work. Is there a way to do this with just a pandas type call?
Full example including data creation:
data = pd.DataFrame(
{
"name": pd.Categorical(["A", "A", "B", "A", "A", "A", "B", "B"]),
"time": [1, 2, 3, 6, 7, 3, 1, 4],
}
)
print(data)
print("======================")
max_table = pd.DataFrame(
{
"name": data.name.unique(),
"max_val": [
data[data["name"] == name].time.max() for name in data.name.unique()
],
}
)
print(max_table)