Bar plot and proportion
(10 points)
Using your own random data from last Friday's forum question, let's use Colab to examine the activity_level
variable. Specifically:
- Generate a bar chart for
activity_level
and - Compute the proportion of folks whose activity level is
high
.
Note that creative burden is higher in this lab than in the last in that the Colab link above leads to a blank notebook. Nonetheless, you can find sample code that should help in our class presentation on Categorical Data.
This discussion has been closed.
Comments
Data Set
Value Counts
Proportion of folks whose activity level is high is: 0.41
Bar Chart
Value count
The proportion whose activity level is high is .26
Bar chart
I generated my own random data with this code:
My data:
I got my value counts with the code:
...and got:
My proportion of people with a high activity level is .35
I got my bar chart with this code:
Here is my data set:
Here is the value counts, which are the data points for my bar chart
Here is my bar chart for activity level, obtained by
I then computed the proportion of folks whose activity level is high, which is .33
high 39
none 31
moderate 30
Name: activity_level, dtype: int64
0.39
Data:
first_name last_name age sex height weight income activity_level
95 Robert Session 20 male 71.36 175.13 2783 high
96 Christine Powers 20 female 65.73 172.88 6692 high
97 Brandon Griffin 23 male 69.00 168.12 31407 moderate
98 Mollie Donohue 39 female 68.95 174.77 15755 high
99 Manuel Hammond 32 male 68.79 146.79 238400 moderate
I also created a table for activity level:
none 35
high 34
moderate 31
Name: activity_level, dtype: int64
Bar Chart:
The proportion of people who were at a high activity level is 0.34
Data Set:
Value Counts Code:
The proportion of high activity level is 0.33
Bar Chart:
My Data Set
The Value Counts of My Data
The Proportion of My Data Set
0.35
The Bar Plot of My Data Set
Data set:
Value counts:
Proportion whose activity is high:
Bar Chart:
Data Set:
Table for the activity level:
My Bar Chart:
The proportion of people who were at a high activity level is 0.33
Data:
Value Counts:
Proportion of people with high activity level: .34
Bar chart:
Data:
to find my specific data for 'activity level'
then i put the data into a bar graph
and i found who was high with this and got 0.27
First I gather the data:
Then I take the value counts from the activity_level variable:
To get the bar chart, I just enter the following code to produce one:
Finally for the proportion data, I just enter this line which returned the value 0.34
And that's all I need to put down.
value counts
proportion
Data
import pandas as pd
df = pd.read_csv('https://www.marksmath.org/cgi-bin/random_data.csv?username=alexa')
df.head()
first_name last_name age sex height weight income activity_level
0 Petrina Jose 37 female 63.10 182.08 22898 high
1 Amanda Abrams 28 female 65.39 126.48 13397 moderate
2 Sandra Howard 55 female 60.88 156.78 31135 moderate
3 Elmer Lim 49 male 66.48 163.43 693 moderate
4 Albert Smith 24 male 72.84 179.31 4438
Variable chart
value_counts = df['activity_level'].value_counts()
value_counts.to_frame()
activity_level
moderate 34
none 34
high 32
Bar Chart
value_counts.plot.bar(figsize=(12,7), rot = 0);
Data:
Value Counts:
Proportion of folks whose activity level is high is: 0.34
Bar:
import dataset:
value counts for desired variable:
finding proportion whose activity level is high:
generate bar graph:
Data Set:
Value Counts:
"High" Proportion:
Bar Chart:
Data:
Value Counts:
Proportion of those with a high activity level:
0.35
Bar Chart:
Data Set
Value Counts
Proportion of people's high activity levels: .32
Data Set:
Value Counts:
| activity_level |\n|:---------|-----------------:|\n| high | 40 |\n| none | 31 |\n| moderate | 29 |
High Proportion:
Bar Chart:
value_counts.plot.bar(figsize=(12,7), rot = 0);
Data Set:
Value Counts:
High Proportion:
.37
Bar Plot:
Data:
Value counts:
Activity level "High":
Bar graph:
My data set:
Value Counts:
high 37
moderate 33
none 30
Name: activity_level, dtype: int64
High Proportion:
0.37
My Bar Chart:
Data set:
df = pd.read_csv ( 'https://www.marksmath.org/cgi-bin/random_data.csv?username=amcbride')
df.head()
Value Counts:
value_counts.to_frame()
moderate 38
high 35
none 27
High proportion:![]
.35
Data:
Value Count
high 36
none 33
moderate 31
High proportion:
0.36
Bar Chart
My Data Set Is:
My Value Counts:
Proportion of people with high activity: .32
Bar Chart:
My data set
My output
Value Counts
Output
Proportion of those who is high-0.36
Bar Chart
import pandas as pd
df = pd.read_csv('https://www.marksmath.org/cgi-bin/random_data.csv?username=Jamon')
df.head()
value_counts = df['activity_level'].value_counts()
value_counts
value_counts.plot.bar(figsize=(12,7), rot = 0);
Data set:
Value Count:
High Proportion Level:
My Bar Chart: