File size: 3,219 Bytes
410d1d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2d034f
 
 
 
 
 
 
 
 
 
 
410d1d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import streamlit as st
import pandas as pd
import numpy as np

def highlight_diff1(row, df1, df2, primary_key):
    styles = []
    name = row.name
    if name in df1.index and name in df2.index:
        index1 = df1.index.get_loc(name)
        index2 = df2.index.get_loc(name)
        for col in df1.columns:
            if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]:
                styles = ['background-color: green'] * len(row)
                break
    elif name in df1.index:
        styles = ['background-color: yellow'] * len(row)
    return styles or [''] * len(row)

def highlight_diff2(row, df1, df2, primary_key):
    styles = []
    name = row.name
    if name in df1.index and name in df2.index:
        index1 = df1.index.get_loc(name)
        index2 = df2.index.get_loc(name)
        for col in df2.columns:
            if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]:
                styles = ['background-color: red'] * len(row)
                break
    elif name in df2.index:
        styles = ['background-color: yellow'] * len(row)
    return styles or [''] * len(row)

def main():
    st.set_page_config(layout="wide")
    st.write("### Input Paths")
    df1_path = st.text_input("Enter Auto_CSV Path:")
    df2_path = st.text_input("Enter OLD Auto_CSV Path:")
    
    
    if not df1_path or not df2_path:
        st.warning("Please enter both CSVs Paths.")
        return
    
    df1 = pd.read_csv(df1_path)
    df2 = pd.read_csv(df2_path)

    primary_column = 'Name'
    common_columns = list(set(df1.columns).intersection(df2.columns))
    common_cols = [x for x in common_columns if x != primary_column]
   
    cols_to_display = st.multiselect("Select Columns to Display", common_cols)
    columns_to_display = cols_to_display + [primary_column]
    col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 6.5, 0.1)
    col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 6.5, 0.1)

    col1, col2 = st.columns([col1_width, col2_width])

    with col1:
        st.write("### Display DataFrame 1")
        if df1 is not None:
            if len(columns_to_display) > 0:
                df1_display = df1[columns_to_display].set_index(primary_column)
                df1_display_styled = df1_display.style.apply(
                    lambda x: highlight_diff1(x, df1_display, df2.set_index(primary_column), primary_column), axis=1)
                st.dataframe(df1_display_styled)
            else:
                st.write("No columns selected")
        else:
            st.write("DataFrame not found")


    with col2:
        st.write("### Display DataFrame 2")
        if df2 is not None:
            if len(columns_to_display) > 0:
                df2_display = df2[columns_to_display].set_index(primary_column)
                df2_display_styled = df2_display.style.apply(
                    lambda x: highlight_diff2(x, df1.set_index(primary_column), df2_display, primary_column), axis=1)
                st.dataframe(df2_display_styled)
            else:
                st.write("No columns selected")
        else:
            st.write("DataFrame not found")

if __name__ == "__main__":
    main()