利用pandas库, 将numpy的array数据保存成csv格式的文件:
import pandas as pd import numpy as np data = pd.read_csv('C:\abc\a.csv', header=None) col1 = data.values[:,0] col2 = data.values[:,1]-0.9 for i in range(0, len(col2)): col2[i] = float("%.2f" % col2[i]) col3 = data.values[:,2] data_arry = [] data_arry.append(col1) data_arry.append(col2) data_arry.append(col3) np_data = np.array(data_arry) np_data = np_data.T np.array(np_data) print(np_data) save = pd.DataFrame(np_data, columns = ['year', 'month', 'day'])
save.to_csv('C:\abc\a_modified.csv',index=False,header=False) #index=False,header=False表示不保存行索引和列标题