脚本宝典收集整理的这篇文章主要介绍了pj_0001_compare_col_csv,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/python# -*- coding: UTF-8 -*-
import pathlibimport pandas as pd
print("please input the 1stfile to compare")csv_from = input()
print("please input the compare column")from_col = input()
print("please input the 2ndfile to compare")csv_to = input()
print("please input the compare column")to_col = input()
print(csv_from)print(from_col)print(csv_to)print(to_col)
#check csv
def _compare_csv(): df_from = pd.read_csv(csv_from) df_to = pd.read_csv(csv_to)
lcol_from = list(df_from[from_col]) lcol_to = list(df_to[to_col])
print("column size of 1st csv is:", len(lcol_from)) print("column size of 2nd csv is:", len(lcol_to))
s1 = set(lcol_from) s2 = set(lcol_to)
ss1 = s1 - s2 ss2 = s2 - s1 print("1st csv - 2nd csv is",ss1) print("2nd csv - 1st csv is",ss2) # ex print("get other col item?") q1 = input() if q1 == 'no': return
print("get from col or to col?") q2 = input()
print("give me a col name") col_name = input()
if q2 == 'from': lcol_other = list(df_from[col_name]) ss_other = ss1 lcol_ref = lcol_from else: lcol_other = list(df_to[col_name]) ss_other = ss2 lcol_ref = lcol_to #ex for 1st - 2nd print("ex col value is:") lout = [] for i in ss_other: lout.append(lcol_other[lcol_ref.index(i)])
print("other col items is:", lout) print("for un_repetition", set(lout)) if __name__ == '__main__': _compare_csv()
以上是脚本宝典为你收集整理的pj_0001_compare_col_csv全部内容,希望文章能够帮你解决pj_0001_compare_col_csv所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。