96abhishekarora commited on
Commit
d1c30b8
·
verified ·
1 Parent(s): 55ec640

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -9,25 +9,24 @@ def convert_df_to_csv(df):
9
  st.title('DataFrame Merger using LinkTransformer')
10
 
11
  # Function to load DataFrame
12
- def load_dataframe(upload, path):
 
13
  if upload is not None:
14
- return pd.read_csv(upload)
15
- elif path != "":
16
- return pd.read_csv(path)
 
17
  else:
18
- return None
19
-
20
  # Options for DataFrame 1
21
  df1_upload = st.file_uploader("Upload DataFrame 1 (CSV)", type=['csv'], key='df1_upload')
22
- df1_path = st.text_input("...or enter path for DataFrame 1 (CSV)", key='df1_path')
23
 
24
  # Options for DataFrame 2
25
  df2_upload = st.file_uploader("Upload DataFrame 2 (CSV)", type=['csv'], key='df2_upload')
26
- df2_path = st.text_input("...or enter path for DataFrame 2 (CSV)", key='df2_path')
27
 
28
  # Load and display the DataFrames
29
- df1 = load_dataframe(df1_upload, df1_path)
30
- df2 = load_dataframe(df2_upload, df2_path)
31
 
32
  if df1 is not None:
33
  st.write("DataFrame 1 Preview:")
@@ -63,4 +62,8 @@ if not df1.empty and not df2.empty:
63
  data=csv,
64
  file_name='merged_dataframe.csv',
65
  mime='text/csv',
66
- )
 
 
 
 
 
9
  st.title('DataFrame Merger using LinkTransformer')
10
 
11
  # Function to load DataFrame
12
+ def load_dataframe(upload):
13
+ ##if csv is uploaded use read_csv to load the data , otherwise use read_excel
14
  if upload is not None:
15
+ if upload.name.endswith('csv'):
16
+ return pd.read_csv(upload)
17
+ else:
18
+ return pd.read_excel(upload)
19
  else:
20
+ return pd.DataFrame()
 
21
  # Options for DataFrame 1
22
  df1_upload = st.file_uploader("Upload DataFrame 1 (CSV)", type=['csv'], key='df1_upload')
 
23
 
24
  # Options for DataFrame 2
25
  df2_upload = st.file_uploader("Upload DataFrame 2 (CSV)", type=['csv'], key='df2_upload')
 
26
 
27
  # Load and display the DataFrames
28
+ df1 = load_dataframe(df1_upload)
29
+ df2 = load_dataframe(df2_upload)
30
 
31
  if df1 is not None:
32
  st.write("DataFrame 1 Preview:")
 
62
  data=csv,
63
  file_name='merged_dataframe.csv',
64
  mime='text/csv',
65
+ )
66
+ else:
67
+ st.write("Please upload or enter paths for both DataFrames.")
68
+
69
+