问题描述
代码和错误(减少了,如果您想查看完整的代码,请参阅最后一部分):
import shutil
import os
filteredCleaned =
'/Volumes/Extreme_SSD/Raymond_Lab/Day_4_RoTarod_Videos_Rotated_if_Necessary_copy/filtered_cleaned_WT_cleaned_YAC128'
if os.path.exists(filteredCleaned):
shutil.rmtree(filteredCleaned)
^显示隐藏文件(按Shift + Command +。),其他目录则显示隐藏文件(如果存在)。
runfile('/Users/ksb7640/Documents/UBC_Academic/Raymond_Lab/448/roTarod/svm_all/data_filter.py',wdir='/Users/ksb7640/Documents/UBC_Academic/Raymond_Lab/448/roTarod/svm_all')
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/IPython/core/interactiveshell.py",line 3417,in run_code
exec(code_obj,self.user_global_ns,self.user_ns)
File "<ipython-input-2-b9676f9bf96c>",line 1,in <module>
runfile('/Users/ksb7640/Documents/UBC_Academic/Raymond_Lab/448/roTarod/svm_all/data_filter.py',wdir='/Users/ksb7640/Documents/UBC_Academic/Raymond_Lab/448/roTarod/svm_all')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py",line 197,in runfile
pydev_imports.execfile(filename,global_vars,local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py",line 18,in execfile
exec(compile(contents+"\n",file,'exec'),glob,loc)
File "/Users/ksb7640/Documents/UBC_Academic/Raymond_Lab/448/roTarod/svm_all/data_filter.py",line 21,in <module>
shutil.rmtree(filteredCleaned)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py",line 715,in rmtree
_rmtree_safe_fd(fd,path,onerror)
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py",line 672,in _rmtree_safe_fd
onerror(os.unlink,fullname,sys.exc_info())
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py",line 670,in _rmtree_safe_fd
os.unlink(entry.name,dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: '._filtered_combined_Experiment2-190630_Day4_145m2_roTarod2_Cam2onRoTarodDeepCut_resnet50_roTarod3Jul17shuffle1_1030000.csv'
问题:
'._filtered_combined_Experiment2-190630_Day4_145m2_roTarod2_Cam2onRoTarodDeepCut_resnet50_roTarod3Jul17shuffle1_1030000.csv'
来自哪里?
我确实使用df.to_csv(csv,index=False)
在filtered_combined_Experiment2-190630_Day4_145m2_roTarod2_Cam2onRoTarodDeepCut_resnet50_roTarod3Jul17shuffle1_1030000.csv
中创建了filtered_cleaned_WT_cleaned_YAC128
,但从未使用chmod
来隐藏它们。
此外,如您在屏幕快照中所见,甚至没有隐藏文件。这是什么错误?
完整代码可能是多余的,但以防万一...(有关事件,缩短的代码,请参见顶部。)
data_filter.py
import shutil
from export_df_to_csv import export_df_to_csv
from extract_parent_current import extract_parent_current
from import_df import *
prefix = 'filtered_'
bound = 0.9
# make a directory for output files
cleanedWT = '/Volumes/Extreme_SSD/Raymond_Lab/Day_4_RoTarod_Videos_Rotated_if_Necessary_copy/cleaned_WT'
cleanedYAC128 = '/Volumes/Extreme_SSD/Raymond_Lab/Day_4_RoTarod_Videos_Rotated_if_Necessary_copy/cleaned_YAC128'
cleanedWTParentDir,WTdir = extract_parent_current(cleanedWT)
cleanedYAC128ParentDir,YAC128dir = extract_parent_current(cleanedYAC128)
filteredCleaned = os.path.join(cleanedYAC128ParentDir,prefix + WTdir + '_' + YAC128dir)
if os.path.exists(filteredCleaned):
shutil.rmtree(filteredCleaned)
os.mkdir(filteredCleaned)
csvs_labels_arr = import_csvs(cleanedWT,cleanedYAC128)
paths_dfs_labels_arr = csvs_to_paths_dfs_labels_arr(csvs_labels_arr)
for path_df_label in paths_dfs_labels_arr:
_,dfFileName = extract_parent_current(path_df_label[0])
df = path_df_label[1]
# filter out rows below bound
df = df[
(df['Rightpaw likelihood'] > bound) & (df['Leftpaw likelihood'] > bound) & (df['Tail likelihood'] > bound)]
export_df_to_csv(df,os.path.join(filteredCleaned,prefix + dfFileName))
export_df_to_csv.py
input_file = '/Volumes/Extreme SSD/Raymond Lab/Day_4_RoTarod_Videos_Rotated_if_Necessary copy/cleaned_WT/cleaned_Experiment2-190630_Day4_145m1_roTarod3_Cam2onRoTarodDeepCut_resnet50_roTarod3Jul17shuffle1_1030000.csv'
output_file = '/Volumes/Extreme SSD/Raymond Lab/Day_4_RoTarod_Videos_Rotated_if_Necessary copy/cleaned_WT/cleaned_Experiment2-190630_Day4_145m1_roTarod3_Cam2onRoTarodDeepCut_resnet50_roTarod3Jul17shuffle1_1030000.csv'
def export_df_to_csv(df,csv):
df.to_csv(csv,index=False)
extract_parent_current.py
import os
def extract_parent_current(dir):
if str.endswith(dir,'/'):
dir = dir[:-1]
return os.path.split(dir)
import_df.py
import os
import random
from copy import deepcopy
import pandas as pd
def import_csvs(WT_file_path,YAC_file_path):
csv_paths_arr = []
for root,dirs,files in os.walk(WT_file_path,topdown=False):
for file in files:
if not file.startswith('.'):
csv_paths_arr.append([os.path.join(root,file),0])
for root,files in os.walk(YAC_file_path,1])
return csv_paths_arr
def csvs_to_paths_dfs_labels_arr(csvpaths_labels_arr):
paths_dfs_labels_arr = deepcopy(csvpaths_labels_arr)
for i,csvpath_label_arr in enumerate(csvpaths_labels_arr):
(paths_dfs_labels_arr[i])[0] = pd.read_csv(csvpath_label_arr[0],encoding='unicode_escape')
paths_dfs_labels_arr[i].insert(0,csvpath_label_arr[0])
return paths_dfs_labels_arr
def import_df(WT_file_path,YAC_file_path):
csv_paths_arr = import_csvs(WT_file_path,YAC_file_path)
dfs_labels = csvs_to_paths_dfs_labels_arr(csv_paths_arr)
random.shuffle(dfs_labels)
return dfs_labels
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)