1.按照间隔生成时间戳,并保存为csv文件
##### 按照间隔生成时间戳,并保存为csv文件
import pandas as pd
from datetime import datetime, time, timedelta
times = []
ts = datetime(2023, 6, 17, 9, 10, 0)
while ts <= datetime(2023, 6, 17, 9, 26, 40):
# times.append(time(ts.hour, ts.minute, ts.second))
times.append(str(ts))
ts += timedelta(seconds=1)
name = ['date']
test = pd.DataFrame(columns=name, data=times)
test.to_csv('./date.csv')
2.读取csv文件的最后一列,并将其绘制为图像
# 绘制A
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('train_Iter0.csv', header=None)
data = np.array(data)
data = data[:,-1]
print(data.size)
data = data.reshape((59,99))
plt.imshow(data)
plt.colorbar()
plt.show()
3.生成一组随机数
import random
random_arrays = []
for _ in range(1000):
random_array = [random.randint(0, 100) for _ in range(24)] # 生成包含10个0-100之间的随机整数的数组
random_arrays.append(random_array)
# 保存数组为txt文件
for i, array in enumerate(random_arrays):
file_name = f"array_{i}.txt"
with open(file_name, "w") as file:
for num in array:
file.write(str(num) + "\n")