Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,52 +28,24 @@ if uploaded_files:
|
|
| 28 |
dataframes.append(df)
|
| 29 |
|
| 30 |
|
| 31 |
-
|
| 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 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
| 62 |
-
|
| 63 |
-
if show_dataframes:
|
| 64 |
-
for i, df in enumerate(dataframes):
|
| 65 |
-
st.write(f"DataFrame {i + 1}")
|
| 66 |
-
st.dataframe(df)
|
| 67 |
-
|
| 68 |
-
if st.button("Download cleaned data"):
|
| 69 |
-
for i, df in enumerate(dataframes):
|
| 70 |
-
csv = df.to_csv(index=False)
|
| 71 |
-
b64 = base64.b64encode(csv.encode()).decode()
|
| 72 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="cleaned_data_{i + 1}.csv">Download cleaned_data_{i + 1}.csv</a>'
|
| 73 |
-
st.markdown(href, unsafe_allow_html=True)
|
| 74 |
-
else:
|
| 75 |
-
st.warning("Please upload CSV file(s).")
|
| 76 |
-
st.stop()
|
| 77 |
|
| 78 |
st.markdown("")
|
| 79 |
st.markdown("---")
|
|
|
|
| 28 |
dataframes.append(df)
|
| 29 |
|
| 30 |
|
| 31 |
+
merge = st.checkbox("Merge uploaded CSV files")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
show_dataframes = st.checkbox("Show DataFrames", value=True)
|
| 36 |
|
| 37 |
+
if show_dataframes:
|
| 38 |
+
for i, df in enumerate(dataframes):
|
| 39 |
+
st.write(f"DataFrame {i + 1}")
|
| 40 |
+
st.dataframe(df)
|
| 41 |
|
| 42 |
+
if st.button("Download cleaned data"):
|
| 43 |
+
for i, df in enumerate(dataframes):
|
| 44 |
+
csv = df.to_csv(index=False)
|
| 45 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
| 46 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="cleaned_data_{i + 1}.csv">Download cleaned_data_{i + 1}.csv</a>'
|
| 47 |
+
st.markdown(href, unsafe_allow_html=True)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
st.markdown("")
|
| 51 |
st.markdown("---")
|