当前位置:网站首页>路测数据合并

路测数据合并

2022-08-11 11:37:00 蕉蕉你要A起来


import pandas as pd
import numpy as np
from pathlib import Path
#路测数据规律探索,预处理

def dushu(load):
    df = pd.concat([pd.read_csv(f1) for f1 in Path(load).rglob('*.csv')],sort = False)
    return df

l='D:\\新大陆\\边际漫游\\手动路测数据\\数据1'
df=dushu(l)

def  tb(df):
    df['lx']=0
    df['lx'].iloc[0:6473]=1
    df['lx'].iloc[6473:7333]=2
    df['lx'].iloc[7333:]=3
    df=df.reset_index(drop=True)    
    return df
df=tb(df)
df1=df.copy()

from dateutil.parser import parse
def hb(df):
    df['bj']=0
    df['bj'].iloc[0]=1
    df['bj'].iloc[len(df)-1]=2

    for i in range(0,8002):
        if df['CellId'].iloc[i]==df['CellId'].iloc[i+1]:
            continue
        else:
            df['bj'].iloc[i]=2
            df['bj'].iloc[i+1]=1
    df_h=df.drop(df[df['bj']==0].index)
    df_h['Time'] =df_h['Time'].apply(lambda x:parse(x)) 
    df_h['dur']=0
    for i in range(len(df_h)):
        if df_h['bj'].iloc[i]==2:
           df_h['dur'].iloc[i] = df_h['Time'].iloc[i] - df_h['Time'].iloc[i-1]
    
    df_h.drop(df_h[df_h['bj']==1].index,inplace=True)
    df_h.drop(['bj'],axis=1,inplace=True)  
    return df_h
df_h=hb(df)
df.to_csv('D:\\新大陆\\边际漫游\\手动路测数据\\数据1\\cl3.csv')       

原网站

版权声明
本文为[蕉蕉你要A起来]所创,转载请带上原文链接,感谢
https://blog.csdn.net/feijiaojiao/article/details/126145781