OatNapat commited on
Commit
b83927e
·
1 Parent(s): dfc4d4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -27,35 +27,35 @@ if uploaded_files:
27
  df = pd.read_csv(file)
28
  dataframes.append(df)
29
 
30
- if len(dataframes) > 1:
31
- merge = st.checkbox("Merge uploaded CSV files")
32
 
33
- if merge:
34
- # Merge options
35
- keep_first_header_only = st.selectbox("Keep only the header (first row) of the first file", ["Yes", "No"])
36
- remove_duplicate_rows = st.selectbox("Remove duplicate rows", ["No", "Yes"])
37
- remove_empty_rows = st.selectbox("Remove empty rows", ["Yes", "No"])
38
- end_line = st.selectbox("End line", ["\\n", "\\r\\n"])
39
-
40
- try:
41
- if keep_first_header_only == "Yes":
42
- for i, df in enumerate(dataframes[1:]):
43
- df.columns = dataframes[0].columns.intersection(df.columns)
44
- dataframes[i+1] = df
45
-
46
- merged_df = pd.concat(dataframes, ignore_index=True, join='outer')
47
-
48
- if remove_duplicate_rows == "Yes":
49
- merged_df.drop_duplicates(inplace=True)
50
-
51
- if remove_empty_rows == "Yes":
52
- merged_df.dropna(how="all", inplace=True)
53
-
54
- dataframes = [merged_df]
55
-
56
- except ValueError as e:
57
- st.error("Please make sure columns match in all files. If you don't want them to match, select 'No' in the first option.")
58
- st.stop()
 
 
59
 
60
  Show or hide DataFrames
61
  show_dataframes = st.checkbox("Show DataFrames", value=True)
 
27
  df = pd.read_csv(file)
28
  dataframes.append(df)
29
 
 
 
30
 
31
+ merge = st.checkbox("Merge uploaded CSV files")
32
+
33
+ if merge:
34
+ # Merge options
35
+ keep_first_header_only = st.selectbox("Keep only the header (first row) of the first file", ["Yes", "No"])
36
+ remove_duplicate_rows = st.selectbox("Remove duplicate rows", ["No", "Yes"])
37
+ remove_empty_rows = st.selectbox("Remove empty rows", ["Yes", "No"])
38
+ end_line = st.selectbox("End line", ["\\n", "\\r\\n"])
39
+
40
+ try:
41
+ if keep_first_header_only == "Yes":
42
+ for i, df in enumerate(dataframes[1:]):
43
+ df.columns = dataframes[0].columns.intersection(df.columns)
44
+ dataframes[i+1] = df
45
+
46
+ merged_df = pd.concat(dataframes, ignore_index=True, join='outer')
47
+
48
+ if remove_duplicate_rows == "Yes":
49
+ merged_df.drop_duplicates(inplace=True)
50
+
51
+ if remove_empty_rows == "Yes":
52
+ merged_df.dropna(how="all", inplace=True)
53
+
54
+ dataframes = [merged_df]
55
+
56
+ except ValueError as e:
57
+ st.error("Please make sure columns match in all files. If you don't want them to match, select 'No' in the first option.")
58
+ st.stop()
59
 
60
  Show or hide DataFrames
61
  show_dataframes = st.checkbox("Show DataFrames", value=True)