Data science code python, Lab Reports of Psychological Data

Code for pie chart using python

Typology: Lab Reports

2022/2023

Uploaded on 10/21/2023

unknown user
unknown user 🇨🇦

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PieChart_Chapter1
September 1, 2023
[1]: import pandas as pd
data =pd.read_csv (r'eg01-02majors.csv')
print(data)
Field of Study Percent
0 ArtsHumanities 8.8
1 BiologicalSciences 15.5
2 Business 13.8
3 Education 4.4
4 Engineering 11.5
5 HealthProf 11.7
6 MathComp 6.2
7 PhysicalSciences 2.7
8 Social Sciences 11.0
9 Other 13.1
[2]: df =pd.DataFrame(data, columns =['Field of Study','Percent'])
df
[2]: Field of Study Percent
0 ArtsHumanities 8.8
1 BiologicalSciences 15.5
2 Business 13.8
3 Education 4.4
4 Engineering 11.5
5 HealthProf 11.7
6 MathComp 6.2
7 PhysicalSciences 2.7
8 Social Sciences 11.0
9 Other 13.1
[3]: import matplotlib.pyplot as plt
fig =df.plot.pie(y='Percent', figsize=(5,5),
labels=df['Field of Study'],legend=False,
title="Percent of Students",label='')
plt.show(fig)
1
pf2

Partial preview of the text

Download Data science code python and more Lab Reports Psychological Data in PDF only on Docsity!

PieChart_Chapter

September 1, 2023

[1]: import pandas as pd

data = pd.read_csv (r'eg01-02majors.csv') print(data)

Field of Study Percent 0 ArtsHumanities 8. 1 BiologicalSciences 15. 2 Business 13. 3 Education 4. 4 Engineering 11. 5 HealthProf 11. 6 MathComp 6. 7 PhysicalSciences 2. 8 Social Sciences 11. 9 Other 13.

[2]: df = pd.DataFrame(data, columns = ['Field of Study', 'Percent']) df

[2]: Field of Study Percent 0 ArtsHumanities 8. 1 BiologicalSciences 15. 2 Business 13. 3 Education 4. 4 Engineering 11. 5 HealthProf 11. 6 MathComp 6. 7 PhysicalSciences 2. 8 Social Sciences 11. 9 Other 13.

[3]: import matplotlib.pyplot as plt fig = df.plot.pie(y='Percent', figsize=(5,5), labels=df['Field of Study'],legend= False , title="Percent of Students",label='') plt.show(fig)

[4]: #saving the figure as a pdf file fig.figure.savefig('piechart.pdf')

[ ]: