[英]how can I infer the candidate key from csv files
我有一個包含 csv 文件的文件夾,其中包含以下文件:car.csv、person.csv、student.csv……每個文件都有列。
我正在嘗試讀取列值並將它們放入列表中。
這是我的功能:
import pandas
from itertools import chain, combinations
def key_options(items):
print(7,items)
return chain.from_iterable(combinations(items, r) for r in range(1, len(items)+1) )
def primary_key_discovery(data_path):
csv_files = glob.glob(os.path.join(data_path, "*.csv"))
for f in csv_files:
dataframes = pd.read_csv(f)
for candidate in key_options(list(dataframes)[1:]):
deduped = dataframes.drop_duplicates(candidate)
if len(deduped.index) == len(dataframes.index):
print(f,','.join(candidate))
print(primary_key_discovery('Data1/'))
這個函數給了我這樣的輸出 Data1\\vehicle.csv model,price,engine-size 我想打印列值,例如 model:camery,altima,aclass,....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.