簡單展示如何利用python中的pandas庫創建、讀取、修改CSV數據文件
import numpy as np
import pandas as pd
# -----create an initial numpy array----- #
data = np.zeros((8,4))
# print(data.dtype)
# print(type(data))
# print(data.shape)
# -----from array to dataframe----- #
df = pd.DataFrame(data)
# print(type(df))
# print(df.shape)
# print(df)
# -----edit columns and index----- #
df.columns = ['A', 'B', 'C', 'D']
df.index = range(data.shape[0])
df.info()
# -----save dataframe as csv----- #
csv_save_path='./data_.csv'
df.to_csv(csv_save_path, sep=',', index