Если у вас есть отдельные строки для ваших агентов и действий, вы можете создать мультииндекс, например:
import pandas as pd
# This is the dataframe data with activities you got from a single agent
agent_1 = [['Phone', 'Phone', 'Coffee', 'Lunch', 'Phone', 'Phone', 'Lunch', 'Lunch'],
['04:00', '08:30', '10:30', '04:00', '10:30', '04:00', '08:30', '10:30']]
# This is the dataframe data from a second agent
agent_2 = [['Phone', 'Pooping', 'Coffee', 'Lunch', 'Phone', 'Meeting', 'Lunch', 'Lunch'],
['08:45', '08:50', '10:30', '04:00', '10:30', '04:00', '08:30', '10:30']]
# We create the dataframe for agent 1
df1 = pd.DataFrame(agent_1).T
df1.columns = ['activity', 'time']
# We create the dataframe for agent 2
df2 = pd.DataFrame(agent_2).T
df2.columns = ['activity', 'time']
# Now we have to dataframes we can't really put together
print(df1)
print("----")
print(df2)
print("----")
# So we should give each dataframe a column with its agent.
df1['agent'] = "Agent_1"
df2['agent'] = "Agent_2"
# Now each dataframe has data on its agent
print(df1)
print("----")
print(df2)
print("----")
# Let's combine them
overview = pd.concat([df1, df2])
print(overview)
print("----")
# To make it even better, we could make a multi-index so we can index both agents AND activities
overview.set_index(['agent', 'activity'], inplace=True)
print(overview)
Вывод:
activity time
0 Phone 04:00
1 Phone 08:30
2 Coffee 10:30
3 Lunch 04:00
4 Phone 10:30
5 Phone 04:00
6 Lunch 08:30
7 Lunch 10:30
----
activity time
0 Phone 08:45
1 Pooping 08:50
2 Coffee 10:30
3 Lunch 04:00
4 Phone 10:30
5 Meeting 04:00
6 Lunch 08:30
7 Lunch 10:30
----
activity time agent
0 Phone 04:00 Agent_1
1 Phone 08:30 Agent_1
2 Coffee 10:30 Agent_1
3 Lunch 04:00 Agent_1
4 Phone 10:30 Agent_1
5 Phone 04:00 Agent_1
6 Lunch 08:30 Agent_1
7 Lunch 10:30 Agent_1
----
activity time agent
0 Phone 08:45 Agent_2
1 Pooping 08:50 Agent_2
2 Coffee 10:30 Agent_2
3 Lunch 04:00 Agent_2
4 Phone 10:30 Agent_2
5 Meeting 04:00 Agent_2
6 Lunch 08:30 Agent_2
7 Lunch 10:30 Agent_2
----
activity time agent
0 Phone 04:00 Agent_1
1 Phone 08:30 Agent_1
2 Coffee 10:30 Agent_1
3 Lunch 04:00 Agent_1
4 Phone 10:30 Agent_1
5 Phone 04:00 Agent_1
6 Lunch 08:30 Agent_1
7 Lunch 10:30 Agent_1
0 Phone 08:45 Agent_2
1 Pooping 08:50 Agent_2
2 Coffee 10:30 Agent_2
3 Lunch 04:00 Agent_2
4 Phone 10:30 Agent_2
5 Meeting 04:00 Agent_2
6 Lunch 08:30 Agent_2
7 Lunch 10:30 Agent_2
----
time
agent activity
Agent_1 Phone 04:00
Phone 08:30
Coffee 10:30
Lunch 04:00
Phone 10:30
Phone 04:00
Lunch 08:30
Lunch 10:30
Agent_2 Phone 08:45
Pooping 08:50
Coffee 10:30
Lunch 04:00
Phone 10:30
Meeting 04:00
Lunch 08:30
Lunch 10:30