import pandas as pd
import numpy as np
import os
def get_file(path):  # 创建一个空列表
    files = os.listdir(path)
    list1 = []
    for file in files:
        if not os.path.isdir(path + file):  # 判断该文件是否是一个文件夹
            f_name = str(file)
            #             print(f_name)
            tr = '\\'  # 多增加一个斜杠
            filename = path + tr + f_name
            #filename =  f_name
            list1.append(filename)#得到所有
    return list1
#f=r'C:\\Users\\Administrator\\Desktop\\combineFile\\cont_Row_01_Col_02_wf.csv'
data2=np.array((range(1,21)))
data3=data2
data4=data2
data5=data2
data6=data2
data7=data2
data8=data2
data9=data2
data10=data2
data11=data2
data12=data2
File=get_file(r'C:\Users\Administrator\Desktop\combineFile')
for varfile in File:
    df = pd.read_csv(varfile, header=None)  # 每个csv文件中的数据
    data1 = np.array(df)  # 把表格转换成数组的格式
    data = data1[:, 18]#提取出时间序列
    c = os.path.splitext(varfile)[0]  # 不含后缀带路径的文件名
    s1 = c.split('\\')[-1]  # 不带后缀的文件名(截取)
    s2 = s1.split('_')[2] + s1.split('_')[-2]#电极号
    i=0
    for varible in data:#循环时间
        if 1.124<=varible<=1.322:
            elnum1=np.append(s2,data1[i,:])
            data3 = np.row_stack((data3, elnum1))
        elif 2.113 <= varible <= 2.311:
            elnum2 = np.append(s2, data1[i, :])
            data4 = np.row_stack((data4, elnum2))
        elif 3.103 <= varible <= 3.301:
            elnum3 = np.append(s2, data1[i, :])
            data5 = np.row_stack((data5, elnum3))
        elif 4.092 <= varible <= 4.290:
            elnum4 = np.append(s2, data1[i, :])
            data6 = np.row_stack((data6, elnum4))
        elif 5.082 <= varible <= 5.280:
            elnum5 = np.append(s2, data1[i, :])
            data7 = np.row_stack((data7, elnum5))
        elif 6.071 <= varible <= 6.269:
            elnum6 = np.append(s2, data1[i, :])
            data8 = np.row_stack((data8, elnum6))
        elif 7.061 <= varible <= 7.259:
            elnum7 = np.append(s2, data1[i, :])
            data9 = np.row_stack((data9, elnum7))
        elif 8.050 <= varible <= 8.248:
            elnum8 = np.append(s2, data1[i, :])
            data10 = np.row_stack((data10, elnum8))
        elif 9.039 <= varible <= 9.237:
            elnum9 = np.append(s2, data1[i, :])
            data11 = np.row_stack((data11, elnum9))
        elif 10.029 <= varible <= 10.227:
            elnum10 = np.append(s2, data1[i, :])
            data12 = np.row_stack((data12, elnum10))
        i=i+1
path2=r'C:\\Users\\Administrator\\Desktop\\splitdata\\'
    #data3=np.insert(data3, 0, values='0102', axis=1)
meansignal3=pd.DataFrame(data=data3[1:])
meansignal3.to_csv(path2+'t1.csv',index=False,header=None)  # 进行数据的保存
meansignal4=pd.DataFrame(data=data4[1:])
meansignal4.to_csv(path2+'t2.csv',index=False,header=None)
meansignal5=pd.DataFrame(data=data5[1:])
meansignal5.to_csv(path2+'t3.csv',index=False,header=None)
meansignal6=pd.DataFrame(data=data6[1:])
meansignal6.to_csv(path2+'t4.csv',index=False,header=None)
meansignal7=pd.DataFrame(data=data7[1:])
meansignal7.to_csv(path2+'t5.csv',index=False,header=None)
meansignal8=pd.DataFrame(data=data8[1:])
meansignal8.to_csv(path2+'t6.csv',index=False,header=None)
meansignal9=pd.DataFrame(data=data9[1:])
meansignal9.to_csv(path2+'t7.csv',index=False,header=None)
meansignal10=pd.DataFrame(data=data10[1:])
meansignal10.to_csv(path2+'t8.csv',index=False,header=None)
meansignal11=pd.DataFrame(data=data11[1:])
meansignal11.to_csv(path2+'t9.csv',index=False,header=None)
meansignal12=pd.DataFrame(data=data12[1:])
meansignal12.to_csv(path2+'t10.csv',index=False,header=None)