Putting a stacked bar into a dataframe - python

I've got a large dataframe and each row has a count of the number of good, okay, bad and other events against it.
I'm trying to replace those 4 columns with a single column that visually represents the same data. i.e. I'd like to replace 4 cells with a single cell containing a stacked horizontal bar
So I want my table to look like the above rather than the like the bottom
I've struggling with the python thus far as the only route I can think of combining them would be to generate each bar seperately in matplotlib, export to jpg and then import into the dataframe.
Which feels like it won't be scaleable...
Any suggestions?

Related

Attempting to plot dataframe with specific rows as the lines and the columns as the xticks

I am trying to plot a line graph that shows multiple lines within my dataframe as the separate lines for comparison i.e. having one as the 'expected' and another to show variations. Additionally, I'm trying to show the columns as the xticks and percentages as the y values:
What I'm trying to show is row 1 as the 'expected' percent and then be able to use any other row i.e. food, bakery products, etc. to show any deviation for that across all columns (serving as the x-axis). I hope that this make sense and any help is appreciated!! I'm a new coder going through a bootcamp.

generate heat map of large array from csv using python

I have a data set that has a somewhat strange layout of the data itself. it looks like this:
It's actually in csv format but I showed it above in excel for convenience.
so the x-axis values are located in the first column. The y-axis values are in the first row. Each blue cell is a data point, with the value in the cell representing an intensity. So the for the top left cell, the coordinates would be [0.000146,0,0]. The one below would be [0.000478,0,114]. I'm trying to figure out how to actually get this data plotted like a 2-D heatmap where the intensity is represented by the color, but haven't been able to do so so far. Any suggestions for how to go about doing this? I've looked at some matplotlib and pandas tutorials but they don't seem to address data formatted this way.

Plot separate histograms from dataframe python

I have a data frame table "pandastable3" that looks like this:
I would like to plot histograms of values for all the columns separately, but so far I am able to get only a single figure containing all the plots together with this to plot the first 3 columns:
pandastable3.hist(layout=(1,2,3))
But I am not sure I am doing that correctly as I cannot visualize anything.
I suppose diff() gives different plots for each column:
pandastable3.diff().hist()

Scatter Plot of a Specific Column in Python using matplotlib

I am very new to Python, but I am determined to learn how to use it. At the moment, I am working with .dat files that have a few columns only separated by spaces.
I was wondering if there is anyway that I can make a scatter plot with a specific column accompanied by each value's non-negative integer? (i.e. 0,1,2,3,4...).
Here is an example of the data I am working with:
Here is an example graph of what I would want to be the end result:

How to plot on box plot 2 data from different data frama - Python

I'm facing a problem to plot 2 box plots into a same graph to make easier to compare them.
The problems is that each box plot comes from a different dataframe with different lenght, however, both have same columns.
My two data frame are:
'headlamp_water' and 'headlamp_crack'; the column I want to use is called 'Use Period'.
How do I do it?
Any help will be highly appreciated
You can concat() the columns and call the boxplot() method.
pd.concat([headlamp_water['Use Period'], headlamp_crack['Use Period']], axis=1).boxplot()
Using axis=1, you select the columns.

Categories

Resources