我有一个包含20个csv文件的文件夹。每个文件大约有10列和数千行。csv文件如下所示:
基因
|
p值
|
xyz
|
棘皮
|
0.05
|
123
|
基质金属蛋白酶2
|
0.02
|
456
|
mmp9
|
0.07
|
789
|
nnos
|
0.09
|
123
|
gfap
|
0.01
|
456
|
我编写了以下脚本,目的是浏览每个文件,并仅根据我指示的感兴趣的基因(在本例中为mmp2和mmp9)过滤行。
# the goal is to edit and save the csv files so they only contain the genes of interest
path = '/Users/adriana/Library/Documents/raw_data',
all_files = glob.glob(os.path.join(path, "*.csv")) #make list of file paths
genes = ["mmp2", "mmp9"]
for file in all_files:
path = '/Users/adriana/Library/Documents/raw_data'
df = pd.read_csv(file,delimiter ='\t')
cleaned = df[df['gene'].isin(genes)]
cleaned.to_csv(file)
但是,我收到以下与创建对象“all_files”有关的错误:
TypeError:应为str、字节或os。PathLike对象,而不是元组
我以前无缝地使用过这个脚本,所以我不确定发生了什么。