Skip to content

Commit

Permalink
script for checking whether two columns are functionally dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Xu committed Mar 14, 2018
1 parent fec573f commit 73e2753
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions check_func_dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pandas as pd
import sys

def check_dep(df, col1, col2):
mp = {}
for idx, row in df.iterrows():
if row[col1] in mp:
if mp[row[col1]] != row[col2]:
return False
else:
mp[row[col1]] = row[col2]
return True

def main():
filename = sys.argv[1]
col1 = sys.argv[2]
col2 = sys.argv[3]
df = pd.read_csv(filename)
if check_dep(df, col1, col2):
print("Functional dependency:", col1, "->", col2)
else:
print("No functional dependency:", col1, " and", col2)

if __name__ == "__main__":
main()

0 comments on commit 73e2753

Please sign in to comment.