I have a dataframe with 5 columns: salesman, vendor, product1, product2 and product3. The dataframe is similar to below:
I want to groupby salesman, loop through 'salesman' index and create a separate stacked bar chart for each salesman. For each stacked bar chart, I want x-axis to be the vendor and y-axis to stack on column values (i.e. product1/2/3 sales amount). Desired output:
Have tried several methods combined with for loop but keep getting error. Appreciate any guidance on this one! Thank you.
Related
I am trying to make a line chart with two metrics vs date. I am querying an already aggregated table. When I add three columns to the visualization, date and 2 numeric fields and pick scatter plot or line chart, only two numeric fields are charted. I want to be able to chart date as X axis and two numeric fields as line chart.
Is there a way to chart two numeric dimensions in one chart without aggregation?
You need to have one dimension, which is the date, and two measures with type:number (because you don't need any aggregation)
measure: total_amount {
type: number
sql: ${pre_aggregated_total_amount} ;;
measure: product_count {
type: number
sql: ${pre_aggregated_product_count} ;;
Also, in the line chart option, you will be able to drag one measure to the left axis and the other one to the right axis if you want.
Hi everyone,
I'm relatively new to python. I want to plot a pie chart for department, i.e., how many percent of the employees coming from Sales & Marketing, Operations, Technology, etc...
I'm not sure how to count the total number of employees from respective department first then only fit the data into the pie chart. Any help will be greatly appreciated!
You can use pandas.Series.value_counts with pandas.Series.plot.pie:
df = pd.DataFrame({"department": ["Sales", "Operations",
"Sales", "Sales", "Technology"]})
df["department"].value_counts().plot.pie()
Output:
I am trying to efficiently plot the number of orders in a seaborn line plot. Here the x-axis should be the date, the y-axis the number_of_orders and there should be a total of 12 lines that correspond to each individual group.
The data I'm working with looks like this. It is a multi index pandas dataframe, where there are several groups for each single date.
Is there an easy way of doing this?
An example on how I want it to look like is this:
try something like this:
sns.lineplot(data=yourDF, x="Date", y="number of orders", hue="Group")
I have a data frame that has persons affected by two different issues for each year from 1999 to 2005 as in bellow image.
dataframe
Can I create a bar chart that shows a comparison of person affected by cancer, Heart disease for each year?
I am reading huge csv file using pandas module.
filename = pd.read_csv(filepath)
Converted to Dataframe,
df = pd.DataFrame(filename, index=None)
From the csv file, I am concerned with the three columns of name country, year, and value.
I have groupby the country names and sum the values of it as in the following code and plot it as a bar graph.
df.groupby('country').value.sum().plot(kind='bar')
where, x axis is country and y axis is value.
Now, I want to make this bar graph as a stacked bar and used the third column year with different color bars representing each year. Looking forward for an easy way.
Note that, year column contains years from 2000 to 2019.
Thanks.
from what i understand you should try something like :
df.groupby(['country', 'Year']).value.sum().unstack().plot(kind='bar', stacked=True)