连线图
import matplotlib
x=[1,2,3,4,5]
y=[2,3,4,5,6]
print(x,y)#[1,2,3,4,5][2,3,4,5,6]
from matplotlib import pyplot as plt
#%matplotlib inline#如果没有图片
fig1=plt.figure(figsize=(5,5))#长宽五英寸的图片
plt.plot(x,y)
plt.title('y vs x')#设置标题
plt.xlabel('x')
plt.ylabel('y')#坐标轴上的标签
plt.show()
散点图
import matplotlib
x=[1,2,3,4,5]
y=[2,3,4,5,6]
print(x,y)#[1,2,3,4,5][2,3,4,5,6]
from matplotlib import pyplot as plt
#%matplotlib inline#如果没有图片
fig2=plt.figure(figsize=(5,5))
plt.scatter(x,y)
plt.title('y vs x')#设置标题
plt.xlabel('x')
plt.ylabel('y')#坐标轴上的标签
plt.show()
numpy使用
import numpy as np
print('A is')
a = np.eye(5)
print(type(a))
print(a)
print('B is')
b = np.ones([5, 5])
print(type(b))
print(b)
print(b.shape)
print('C is')
c = a+b
print(type(c))
print(c.shape)
print(c)
# A is
# <class 'numpy.ndarray'>
# [[1. 0. 0. 0. 0.]
# [0. 1. 0. 0. 0.]
# [0. 0. 1. 0. 0.]
# [0. 0. 0. 1. 0.]
# [0. 0. 0. 0. 1.]]
# B is
# <class 'numpy.ndarray'>
# [[1. 1. 1. 1. 1.]
# [1. 1. 1. 1. 1.]
# [1. 1. 1. 1. 1.]
# [1. 1. 1. 1. 1.]
# [1. 1. 1. 1. 1.]]
# (5, 5)
# C is
# <class 'numpy.ndarray'>
# (5, 5)
# [[2. 1. 1. 1. 1.]
# [1. 2. 1. 1. 1.]
# [1. 1. 2. 1. 1.]
# [1. 1. 1. 2. 1.]
# [1. 1. 1. 1. 2.]]
pandas
import pandas as pd
data=pd.read_csv('')#导入文件
x=data.loc[:,'x']#x所有的数据
c=data.loc[:,'x'][y>50]#对数据进行筛选
import numpy as np
data_array=np.array(data)#把data转换为array
data_new=data+10
data_new.head()#看见部分数据
data_new.to_csv('****.csv')#保存数据