python實現代碼如下
import csv
import datetime
import pandas as pd
if __name__ == '__main__':
## 文件路徑
csv_path = './data/ganglia-metrics.csv'
## Export file naming
new_csv_name = "new_ganglia-metrics.csv"
## 讀取csv信息
data = pd.read_csv(csv_path)
## I only have two columns of data,Two arrays are defined,After processing, store it in the array,Finally save the output
timestampList = []
cpu_idleList = []
# 修改csvA column of data information
for i in range(data.shape[0]):
# 修改格式
t = (datetime.datetime.strptime(data.loc[i]['Timestamp'], "%Y-%m-%dT%H:%M:%S+00:00") + datetime.timedelta(
hours=2)).strftime("%Y-%m-%d %H-%M-%S")
# 寫入數組
timestampList.append(t)
cpu_idleList.append(data['cpuIdle'][i])
# 寫出到csv
with open(new_csv_name, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
# 先寫入columns_name
writer.writerow(["Timestamp", "cpuIdle"])
for i in range(len(timestampList)):
writer.writerow([timestampList[i], cpu_idleList[i]])