pj_0001_compare_col_csv

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pathlib
import 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()

posted @   小葱饼子  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示