python写data.csv
1.# 建立csv文件并读取
with open(“data1.csv”, “w”) as csvfile:
writer = csv.writer(csvfile)
writer.writerows([[0, 0], [500, 500], [1000, 2000], [2000, 4000], [2300, 5000], [6000, 12000]])
with open(“data.csv”, “r”) as csvfile:
reader = csv.reader(csvfile)
# 这里不需要readlinesa
for line in reader:
print(line)
points = np.genfromtxt(“data1.csv”, delimiter=",") # 全局变量
#points
#提取points中的两列数据,分别作为x,y
x = points[:, 0]
y = points[:, 1]
#用plt画出散点图看一下
plt.scatter(x, y)
plt.show()
2.直接在左边创建.csv文件然后写入数据
points = np.genfromtxt(“data1.csv”, delimiter=",") # 全局变量,dtype = None
#points
提取points中的两列数据,分别作为x,y
x = points[:, 0]
y = points[:, 1]
#用plt画出散点图看一下
plt.scatter(x, y)
plt.show()
data.csv
最新推荐文章于 2024-08-19 14:47:08 发布