#Bar Graph

86 messages · Page 1 of 1 (latest)

prime light
#

I want to make a bar graph with the amount of males and females working at a certain company. The values are 1 if they individual is female and 0 if the individual is male. However, I don't know how to do the code. I have the excel file, would anyone be able to help me with figuring out how I would do it?

tribal jetty
prime light
#

Sorry, would you mind explaining what that means, when it comes to coding I am a feotus

tribal jetty
#

Ummm no worries

#

Do you know the basics of python?

prime light
#

Um, I know how to do addition and stuff

#

And print

#

And also how to load files

#

Like the CSV stuff

#

I just get stuck whenever I try to do graphs, like information like this:

#

I just want to go the Y axis be Frequency and then the X axis be Male and Female but I have no clue how I go about doing that without it looking like one big blob

tribal jetty
#

Have you tried any code so far?

prime light
#

Yes I have

#

I know about lexis files, pandas and currently I'm working on networking

#

I just get confused by working on graphs 😦

#

Also thanks for responding I thought everyone was just gonna ignore my question 😄

tribal jetty
#

No worries lol, this is my field of expertise

#

If you know about pandas, have a look at matplotlib

#

Matplotlib will allow you to make the plots you want

prime light
#

Okay, I know of pandas but I'm not very good at using it, how do I look at matplotlib, is it a place?

tribal jetty
#

Google it

#

It's a library like pandas

#

Actually, if you just want a rough plot, you can directly use pandas I think

prime light
#

Okay, how do I use pandas, is it a command I have to put in?

#

I thought pandas was what they called the graphs

tribal jetty
#

Huh

#

I think you've lost me lol

prime light
#

Yeah sorry I'm really bad at this ;-;

#

The course I took was coding from nothing to basic but the professor has just skyrocketed in teaching and everything makes no sense to me

#

So that's why I'm asking for help

tribal jetty
#

Pandas is a python library, which in other words is a collection of code that has been written by other people that you can use. What pandas is good at is tabular data, so like the spreadsheets you use in excel

prime light
#

Ah yes I have excel that's what the information I'm using is on

tribal jetty
#

Pandas has functions to read in tabular data files like csv or xlsx files into something called a data frame. This data frame is similar to what you see in excel. From this data frame, you can apply things to it to do what you want like plotting a certain column's data

prime light
#

Yes, those are like df1 and df2 right?

#

I know about those

tribal jetty
#

Maybe, I assume that's what you've called your data frames

prime light
#

mhm

#

When I click on them in spyder it displays the information from the CSVs

#

Excel, or whatever they're called

tribal jetty
#

Okay

#

What do your data frames look like?

prime light
#

There's more but I can't fit it all in but this is the general gist

tribal jetty
#

Okay no worries

#

So you've seemed to have successfully loaded in the data

prime light
#

Yay 😄

tribal jetty
#

Do you know how to select a series i.e. a column from your data frame?

prime light
#

How would one do that?

tribal jetty
#

It'll be like dataframename["column_name"]

#

Where obviously you use the data frame and column names you have/want

prime light
#

Okay, and that would select that column?

tribal jetty
#

Try it and see what you get

prime light
#

Does this look like a step in the right direction?

tribal jetty
#

What do you think? Does that look like the column you want

prime light
#

Well it's the column that says 1s and 0s: 1 Meaning they are female and 0 meaning that they are male

#

And I believe that those numbers on the left is a count ? From 0 to the max amount?

tribal jetty
#

Well the left hand numbers are the indez

#

Index so the row number

prime light
#

Ah thank you, so yes this is the column out of the information I wish to select

tribal jetty
#

Okay

#

Try use .plot() on that column

prime light
#

What I put the name of the column inbetween the brackets/

#

?

tribal jetty
#

You don't put anything in

prime light
#

it says invalid syntax

tribal jetty
#

Put them together

prime light
#

Oh sorry

#

My bad

#

I get this

tribal jetty
#

Oh facts

#

Well it seems like by default it plotted a line graph

#

Do .plot(kind="bar") instead

#

Hopefully it should give you a bar plot

prime light
#

Okie, I did that and it gave me this

tribal jetty
#

Wtf

prime light
#

Yup

#

I say the same, I have no clue why it's doing that

tribal jetty
#

Oh okay I get it

#

What it's for is plot each row individually

prime light
#

Okay, I see, what I wanted it to do is to plot 'Male' and 'Female' and then on the Y axis it says 'Frequency'

tribal jetty
#

Umm I think you'll want to groupby the female column, and then grab the counts before plotting it

#

But I think I've given you enough for you to learn to Google it yourself