制作数据集(5)

今天把之前写的代码组合成为一个函数,可以直接调用,代码更清爽。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
def read_csv(inputdir):
df = pd.read_csv(inputdir, header=None, usecols=[1])
df = df.drop(index=[0, 1])
df = df.astype(float)
return df

def x_split_one_csv(df, befor_start, cycle):
befor_end = befor_start + (cycle * 588)
x = df[befor_start:befor_end]
x = x.astype(float)
return x

def y_split_one_csv(df, after_start, cycle):
after_end = after_start + (cycle * 588)
y = df[after_start:after_end]
y = y.astype(float)
return df_after

def plt_wave(df):
pd.DataFrame(df).plot(figsize=(8,5))
plt.grid(True)
plt.show()

def merge(stress_befor, stress_after):
outfile = stress_befor.append(stress_after)
outfile = outfile.astype(float)
return outfile

x代表a波,是一个(588,1)的时间序列
y代表c波,是一个(588,1)的时间序列