Data Analysis and Display - Three Modules

Keywords: pip

Write a custom directory title here

Data Analysis and Display - Three Modules

Before learning how to crawl some useless data, now learn about data analysis
The three modules of learning are:
import pandas
import numpy
import matplotlib

install

pip installation website + download corresponding version of whl file + pip installation command

Basic concepts

Multidimensional data: list type
High-dimensional data: dictionary type

Basic usage of numpy Library

Creating N-Dimensional Array Objects: ndarray

import numpy


# CalculationA**2+B**3The value of theA,BIt's a one-dimensional array, and the conventional solution is to take it out one by one and add it up by using a loop.
def pysum():
	a = [0,1,2,3,4]
	b = [9,8,7,6,5]
	c = []
	for i in range(len(a)):
		c.append(a[i]**2+b[i]**3)

	return c


print(pysum())


# CalculationA**2+B**3The value of theA,BIt's a one-dimensional array, and the conventional solution is to use the loops to extract and add one by one.NDimensional array objects: ndarray
def npsum():
	# numpy.array()generate ndarray array
	a = numpy.array([0,1,2,3,4])
	b = numpy.array([9,8,7,6,5])
	return a**2+b**3


print(npsum())

The data types returned are also different:
[729, 513, 347, 225, 141]
[729 513 347 225 141]

Printing N-Dimensional Array Objects: Some Properties of ndarray

import numpy


a = numpy.array([[1,2,3,4,5],[2,3,4,5,6]])
zhi = a.ndim
juzhen = a.shape
length = a.size
type = a.dtype
single_size = a.itemsize
print("Rank(dimension)Quantity:"+str(zhi))
print("N Dimensional array object scale (i.e. rows and columns):"+str(juzhen))
print("N Length of Dimensional Array Objects( m That's ok*n Column):"+str(length))
print("N Types of Dimensional Array Objects:"+str(type))
print("N The size of each element of the dimension array object:"+str(single_size))

Basic Use of matplotlib Library

Axis of coordinates

#@Time : 2019/4/19 12:59
#@Author  :Waiter
#@File :1.py


import matplotlib.pyplot as plt

input_values = [1,2,3,4,5]
squares = [1,4,9,16,25]
# plot()Functions are used to draw images
# linewidth attributes control the thickness of lines
plt.plot(input_values,squares,linewidth=5)
# Setting title-related properties
plt.title("Square Numbers",fontsize=24)
# Setting labels for x and y axes
plt.xlabel("x:",fontsize=14)
plt.ylabel("y=x**2:",fontsize=14)
# Set the size of the scale marker
plt.tick_params(axis='both',labelsize=14)
plt.show()

The effect is as follows:

Scatter plot

Posted by thatsme on Fri, 19 Apr 2019 19:33:33 -0700