Exercise of unit06 common library

Exercise of unit 6 common library

2020/6/14 unit6

Title:

  1. Read data file in external CSV format GDP.csv , remove the rows with missing data, and store the remaining data in CSV format in the same folder as GDP_new.csv File.

  2. Read data file GDP in external CSV format_ new.csv , take Year as the independent variable, CPI as the dependent variable, set the line as the solid line, set the point as the solid point, set the color as green, and draw the horizontal line at the vertical coordinate y=1. Add coordinate axis label, abscissa label is "Year", ordinate label is "CPI", graph title is "Figure", and use legend to add legend introduction.

  3. Read data file GDP in external CSV format_ new.csv , extract the first 30 rows of data, take Kapital as the independent variable, GDP as the dependent variable, draw a scatter chart, set the scatter size to 15, the shape to "*", and the color to red. Add a coordinate axis label, the abscissa label is "Kapital", the ordinate label is "GDP", the graph title is "The scatter figure of GDP and Kapital", the abscissa range is set to 02000, and the ordinate range is set to 08000.

  4. Read data file GDP in external CSV format_ new.csv , extract CPI, draw the box shape with grooves, display the mean value and express it with lines. The box is placed vertically, the internal color is set as yellow, the frame is green, the size of the figure is set as width 4 height 6, the label under the box is "CPI", and the title of the whole figure is set as "The boxplot of CPI".

  5. Read data file GDP in external CSV format_ new.csv , extract KR, respectively draw KR frequency distribution histogram (bar number is 6, color is set to green, X-axis label is "KR", graphic label is "frequency"), frequency distribution histogram (bar number is 6, color is set to red, X-axis label is "KR", graphic label is "PDF") and cumulative distribution histogram (bar number is 6, color is set to Pink, X-axis label "KR", graphic label "CDF")

  6. Given the height data of a class, the number of students distributed in 150-160160-170170-180 and 180 is 5, 28, 35, and 4 respectively. Draw a pie chart with shadow. The distance away from the center of each pie chart is 0, 0.1, 0, 0.1 respectively. The color is set as yellow, green, blue and pink respectively. The label displayed on the outside of each pie chart is 150-160160-170170-180 respectively, 180 ", the radius of pie chart is set to 0.8, drawn clockwise from the positive direction of y axis, and the percentage in pie chart is set to two decimal places.

code:

1

import os
os.getcwd()
os.chdir('/Users/janine/documents')
import pandas as pd
# pd.read_csv("GDP.csv")
data0 = pd.read_csv("GDP.csv")
data = data0.dropna()
# GDP of remaining data stored in the same folder in CSV format_ new.csv
data.to_csv('/Users/janine/documents/GDP_new.csv')

2

data = pd.read_csv("GDP_new.csv")

import matplotlib.pyplot as pl
pl.plot(data['Year'],data['CPI'],linestyle='-',marker='o',c='green',label='Figure')
pl.axhline(y=1)  # Draw a horizontal line at y=1
pl.xlabel('Year')
pl.ylabel('CPI')  # Set horizontal and vertical axis names
pl.legend()  # Using legend to add legend introduction
pl.show()

3

data = pd.read_csv("GDP_new.csv")
data3 = data[0:30]

import matplotlib.pyplot as pl
x = data3['Kapital']
y = data3['GDP']

pl.scatter(x,y,s=15,c='r',marker='*')
pl.xlabel('Kapital')
pl.ylabel('GDP')  # Set horizontal and vertical axis names
pl.title("The scatter figure of GDP and Kapital")  # Graphic title
pl.xlim(range(0,2001))  #Abscissa range setting
pl.ylim(range(0,8001))
pl.show()

4

data = pd.read_csv("GDP_new.csv")
data4 = data['CPI']    # Extract CPI
pl.figure(figsize=(4,6))  # Graph size set to width 4 height 6
pl.boxplot(data4, notch=True, labels=['CPI'], patch_artist=True, meanline=True, showmeans=True, boxprops = {'color':'green','facecolor':'yellow'})
pl.title("The boxplot of CPI")

5

data = pd.read_csv("GDP_new.csv")
data5 = data['KR']
pl.hist(data5, bins=6, color='green')
pl.xlabel('KR')
pl.title('frequency')

# PDF probability distribution
pl.hist(data5, bins=6, density=True,color='r')
pl.xlabel('KR')
pl.title('PDF')

# CDF cumulative probability function
pl.hist(data5, bins=6, density=True, color='pink', cumulative=True)
pl.xlabel('KR')
pl.title('CDF')

6

x = [5,28,35,4]
labels=['150-160','160-170','170-180','180']
colors=['yellow','green','blue','pink']
pl.pie(x, explode=(0, 0.1, 0, 0.1), labels=labels, colors=colors, shadow=True, startangle=90, radius=0.8, counterclock=False, autopct='%1.2f%%')

Added by miligraf on Sun, 14 Jun 2020 05:12:17 +0300