代码和错误(减少,如果您想查看完整代码,请参阅最后一节):
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/[email protected] /cdn-cgi/l/email-protection/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/[email protected] /cdn-cgi/l/email-protection/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/[email protected] /cdn-cgi/l/email-protection/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
in filtered_cleaned_WT_cleaned_YAC128
但我从来没有用过chmod
隐藏它们。
此外,正如您在屏幕截图中看到的,甚至没有隐藏文件。错误是什么?
完整的代码可能是多余的,但以防万一......(有关相关的缩短代码,请参见顶部。)
数据过滤器.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))
导出_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)
导入_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, dirs, files in os.walk(YAC_file_path, topdown=False):
for file in files:
if not file.startswith('.'):
csv_paths_arr.append([os.path.join(root, file), 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