我有一个庞大的学生数据集,每个学生都有自己的csv文件, 数据集B有297444个csv文件,我想知道该数据集中缺少哪个学生csv文件
如图所示,该数据集中没有u2.csv文件,因此如何使用pandas检查丢失的所有csv文件
这是我到目前为止试过的代码
import pandas as pd
import numpy as np
import glob
path = r'C:/Users/user1/Desktop/EDNET DATA/EdNet-KT4/KT4' # use your path
all_files = glob.glob(path + "/*.csv")
li = []
for i,filename in enumerate (all_files):
df = pd.read_csv(filename, ',' ,index_col=None, header=0).assign(user_iD=filename.split("\\")[-1].split(".")[0])
li.append(df)
data = pd.concat(li, axis=0, ignore_index=True)
df = data.copy()
df.isnull().sum()
df.to_feather('KT4.ftr')
data1= pd.read_feather('KT4.ftr')
data1.head()
解决方案
您可以选择使用以下两种方法中的任何一种。为了再现性,我创建了一些虚拟数据,并在Google Colab上测试了解决方案。我发现使用熊猫(方法2)在某种程度上更快
通用代码
方法1:简单Python循环
100,000
文件,在googlecolab上大约花了1分钟29秒李>方法2:使用熊猫库进行处理(更快)🔥🔥🔥
100,000
文件,在googlecolab上大约花费了358毫秒李>虚拟数据
在这里,我将定义一些虚拟数据,以便 该溶液重现性好,易于测试
我将跳过以下学生ID(
skip_student_ids
),并且不会为它们创建任何.csv
文件参考资料
^{} - Docs
Can I add message to the tqdm progressbar?
相关问题 更多 >
编程相关推荐