Reputation: 43593
import pandas as pd
import matplotlib.pyplot as plt
my_funds = [10, 20, 50, 70, 90, 110]
my_friends = ['Angela', 'Gabi', 'Joanna', 'Marina', 'Xenia', 'Zulu']
my_actions = ['sleep', 'work', 'play','party', 'enjoy', 'live']
df = pd.DataFrame({'Friends': my_friends, 'Funds':my_funds, 'Actions': my_actions})
produces:
Then, I am plotting it like this:
df.plot (kind='bar', x = "Friends" , y = 'Funds', color='red', figsize=(5,5))
getting the following:
What is the goal?
The same graph, but instead of "Angela" to have "Angela - sleep" written on the x-axis. The "sleep" comes from the "Action" column.
Further [Gabi - work, Joanna - play, Marina - party, Xenia - enjoy, Zulu - live]
Upvotes: 0
Views: 53
Reputation: 18377
For the sake of this question it is easier to create an extra column with the values you desire and then pass it to the df.plot()
:
df['Friends_actions'] = df['Friends'] + " " + df['Actions']
df.plot(kind='bar', x = "Friends_actions" , y = 'Funds', color='red', figsize=(5,5))
Upvotes: 2
Reputation: 272
A solution could be to create a new column in your DataFrame:
df["Friend-Action"] = [f"{friend} -> {action}" for friend, action in zip(df["Friends"], df["Actions"])]
Then, plot this column:
df.plot (kind='bar', x = "Friend-Action" , y = 'Funds', color='red', figsize=(5,5))
Upvotes: 2