jkushwaha commited on
Commit
410d1d3
·
verified ·
1 Parent(s): e462bfe

Create CSV_UI.py

Browse files
Files changed (1) hide show
  1. CSV_UI.py +88 -0
CSV_UI.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ def highlight_diff1(row, df1, df2, primary_key):
6
+ styles = []
7
+ name = row.name
8
+ if name in df1.index and name in df2.index:
9
+ index1 = df1.index.get_loc(name)
10
+ index2 = df2.index.get_loc(name)
11
+ for col in df1.columns:
12
+ if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]:
13
+ styles = ['background-color: green'] * len(row)
14
+ break
15
+ elif name in df1.index:
16
+ styles = ['background-color: yellow'] * len(row)
17
+ return styles or [''] * len(row)
18
+
19
+ def highlight_diff2(row, df1, df2, primary_key):
20
+ styles = []
21
+ name = row.name
22
+ if name in df1.index and name in df2.index:
23
+ index1 = df1.index.get_loc(name)
24
+ index2 = df2.index.get_loc(name)
25
+ for col in df2.columns:
26
+ if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]:
27
+ styles = ['background-color: red'] * len(row)
28
+ break
29
+ elif name in df2.index:
30
+ styles = ['background-color: yellow'] * len(row)
31
+ return styles or [''] * len(row)
32
+
33
+ def main():
34
+ df1 = pd.DataFrame({
35
+ 'Name': ['John', 'Alice', 'Bob', 'Mad'],
36
+ 'Age': [25, 30, 22, 77],
37
+ 'Location': ['New York', 'Los Angeles', 'Chicago', 'Noida']
38
+ })
39
+
40
+ df2 = pd.DataFrame({
41
+ 'Name': ['John', 'Alice', 'Bob', 'Panda'],
42
+ 'Age': [25, 30, 43, 27],
43
+ 'Location': ['New York', 'Delhi', 'Chicago', 'London'],
44
+ 'Loc': ['NewYork', 'bkjk', 'Chicdfsdago', 'Lofsfndon']
45
+ })
46
+
47
+ st.set_page_config(layout="wide")
48
+ st.write("### Input Paths")
49
+ primary_column = 'Name'
50
+ common_columns = list(set(df1.columns).intersection(df2.columns))
51
+ common_cols = [x for x in common_columns if x != primary_column]
52
+
53
+ cols_to_display = st.multiselect("Select Columns to Display", common_cols)
54
+ columns_to_display = cols_to_display + [primary_column]
55
+ col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 6.5, 0.1)
56
+ col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 6.5, 0.1)
57
+
58
+ col1, col2 = st.columns([col1_width, col2_width])
59
+
60
+ with col1:
61
+ st.write("### Display DataFrame 1")
62
+ if df1 is not None:
63
+ if len(columns_to_display) > 0:
64
+ df1_display = df1[columns_to_display].set_index(primary_column)
65
+ df1_display_styled = df1_display.style.apply(
66
+ lambda x: highlight_diff1(x, df1_display, df2.set_index(primary_column), primary_column), axis=1)
67
+ st.dataframe(df1_display_styled)
68
+ else:
69
+ st.write("No columns selected")
70
+ else:
71
+ st.write("DataFrame not found")
72
+
73
+
74
+ with col2:
75
+ st.write("### Display DataFrame 2")
76
+ if df2 is not None:
77
+ if len(columns_to_display) > 0:
78
+ df2_display = df2[columns_to_display].set_index(primary_column)
79
+ df2_display_styled = df2_display.style.apply(
80
+ lambda x: highlight_diff2(x, df1.set_index(primary_column), df2_display, primary_column), axis=1)
81
+ st.dataframe(df2_display_styled)
82
+ else:
83
+ st.write("No columns selected")
84
+ else:
85
+ st.write("DataFrame not found")
86
+
87
+ if __name__ == "__main__":
88
+ main()