表格数据格式错误的自动检测
forma的Python项目详细描述
Forma公司
Forma是一个用python编写的开放源代码库,它支持对表格数据进行自动的、与域无关的格式错误检测。这个图书馆是研究项目BigDataStack的副产品。在
安装
运行pip install forma
在您的环境中安装库。在
如何使用
我们将使用流行的movielens数据集。在
# local# load the datacol_names=['user_id','movie_id','rating','timestamp']ratings_df=pd.read_csv('../data/ratings.dat',delimiter='::',names=col_names,engine='python')^{pr2}$
让我们介绍一些随机错误。在
# localdirty_df=ratings_df.astype('str').copy()dirty_df.iloc[3]['timestamp']='9783000275'dirty_df.iloc[2]['movie_id']='914.'dirty_df.iloc[4]['rating']='10'
初始化探测器,安装并检测。返回的结果是一个pandas数据帧,其中有一个额外的列p
,它记录在行中出现格式错误的概率。我们看到元组中引入随机人工错误的概率增加了。在
# local# initialize detectordetector=FormatDetector()# fit detectordetector.fit(dirty_df,generator=PatternGenerator(),n=3)# detect error probabilityassessed_df=detector.detect(reduction=np.mean)# visualize resultsassessed_df.head()
100%|██████████| 4/4 [02:58<00:00, 44.58s/it]
100%|██████████| 1000209/1000209 [07:28<00:00, 2230.59it/s]
- 项目
标签: