预处理1

若如初见. 提交于 2020-01-17 07:54:46
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os,time,sys
import xlrd
path='./train/'
path_name=os.listdir(path)
tuo=[]
wei=[]
ci=[]
for i in path_name:
    #i=str(i)
    df = pd.read_csv(path+i)
    if df['type'][0]== '拖网':
        tuo.append(i)
    elif df['type'][0]== '刺网':
        ci.append(i)
    else:
        wei.append(i)
        #分数据
def divide_data(data_name,path,X_data):
    for i in data_name:
        i=str(i)
        df = pd.read_csv(path + i)
        X_data.append(df)
    return X_data
    
tuo_data=[]
wei_data=[]
ci_data=[]
Tuo_data=divide_data(tuo,path,tuo_data)  
Wei_data=divide_data(wei,path,wei_data) 
Ci_data=divide_data(ci,path,ci_data)
 
Tuo_data = pd.concat(Tuo_data)   
Wei_data = pd.concat(Wei_data) 
Ci_data = pd.concat(Ci_data) 

Ci_v=np.array(Ci_data['速度'])
Wei_v=np.array(Wei_data['速度'])
Tuo_v=np.array(Tuo_data['速度'])

plt.figure(figsize=(20,5))
plt.plot(Tuo_v)
plt.plot(Ci_v)
plt.plot(Wei_v)
Ci_v=np.where(Ci_v >20,20,Ci_v)
Tuo_v=np.where(Tuo_v>20,20,Tuo_v)
Wei_v=np.where(Wei_v>20,20,Wei_v)

n, bins, patches = plt.hist(Ci_v, 100, normed=True, rwidth=0.8)
n, bins, patches = plt.hist(Tuo_v, 100, normed=True, rwidth=0.8)
n, bins, patches = plt.hist(Wei_v, 100, normed=True, rwidth=0.8)

plt.hist(Ci_v,100,normed=True,rwidth=0.8)
plt.hist(Wei_v,50)
plt.hist(Tuo_v,50)
plt.bar(Ci_v,100)  


for name in path_name:
    for i in tuo:    
    df = pd.read_csv(path + name)
    df = df.iloc[::-1]
    df_feat = [df['渔船ID'].iloc[0]]
    jingdu=np.array(df['x'])
    weidu=np.array(df['y'])
    plt.figure(figsize=(10,5))
    plt.savefig("./img/"+ name +".png")

 
在这里插入代码片

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!