用cmd命令获取当前文件夹下所有文件名列表
来到当前目录下,在地址栏输入cmd进入当前目录dir …/b>aaaa.txt
用pandas读取csv数据,进行处理并存为txt/dat格式
import os
import pandas as pd
#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)
#设置value的显示长度为100,默认为50
pd.set_option('max_colwidth',100)
# get the path of current python file
path = os.getcwd()
# get the path of current python file
dir = os.listdir(path)
for i in range(6, len(dir)):
# header refers to which line is the header, delimiter = ',' will cause error, so use '\t' means tab
data = pd.read_csv(dir[i], header=9, sep=',')
j = 0
length = len(data)
while j < len(data):
if data.values[j][2] == -1 or data.values[j][3] == -1 or data.values[j][4] == -1 or data.values[j][5] == -1:
data = data.drop([j])
data = data.reset_index(drop = True)
else:
j = j + 1
da = data.loc[:, ['LeftGazePoint2dX', 'LeftGazePoint2dY', 'RightGazePoint2dX', 'RightGazePoint2dY']]
validrate = len(da) / length
if validrate > 0.7:
da.to_csv(dir[i].strip('.csv')+'.dat', header = False, index = False, sep = '\t')
print(dir[i],'selected, validrate is', validrate)