第八讲练习
原始方法:
data1_stock = np.loadtxt("C:\\Users\\chen\\Desktop\\python-m notebook\\图片及数据\\大地电磁EMD数据\\EMD1.csv",delimiter=",",dtype="object")
data2_stock = np.loadtxt("C:\\Users\\chen\\Desktop\\python-m notebook\\图片及数据\\大地电磁EMD数据\\EMD2.csv",delimiter=",",dtype="object")
v_data = np.vstack((data1_stock,data2_stock))#行堆叠
print(v_data.shape)
np.savetxt("all_data.csv",v_data,delimiter=',',fmt="%s")#保存
方法2,封装:
def vstack_data(*args):#使用*args可以读取全部文件
data_list = []
for file_name in args:
per_data = np.loadtxt(f"{file_name}",delimiter=",",dtype="object")
data_list.append(per_data)
print(len(data_list))
#数据堆叠
v_data = np.vstack(data_list)
np.savetxt("all_data2.csv",v_data,delimiter=",",fmt="%s")
vstack_data("C:\\Users\\chen\\Desktop\\python-m notebook\\图片及数据\\大地电磁EMD数据\\EMD1.csv","C:\\Users\\chen\\Desktop\\python-m notebook\\图片及数据\\大地电磁EMD数据\\EMD2.csv")