Spaces:
No application file
No application file
File size: 1,772 Bytes
5742bb7 |
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 |
import streamlit as st
import pandas as pd
# Function to export data based on format choice
def export_data(data, format_choice):
if format_choice == 'CSV':
data.to_csv('exported_data.csv', index=False)
elif format_choice == 'JSON':
data.to_json('exported_data.json', orient='records')
elif format_choice == 'Excel':
data.to_excel('exported_data.xlsx', index=False)
else:
st.error("Unsupported format choice!")
# Streamlit app
def main():
st.title("Research Data Export")
# File upload section
st.header("Upload your data")
uploaded_file = st.file_uploader("Choose a file", type=["csv", "json", "xlsx"])
if uploaded_file is not None:
file_extension = uploaded_file.name.split(".")[-1]
try:
if file_extension == 'csv':
data = pd.read_csv(uploaded_file)
elif file_extension == 'json':
data = pd.read_json(uploaded_file)
elif file_extension in ['xlsx', 'xls']:
data = pd.read_excel(uploaded_file)
else:
st.error("Unsupported file format!")
return
st.success("Data loaded successfully!")
# Display loaded data
st.subheader("Loaded Data")
st.dataframe(data)
# Format export section
st.header("Export your data")
export_format = st.selectbox("Select export format", ["CSV", "JSON", "Excel"])
if st.button("Export"):
export_data(data, export_format)
st.success(f"Data exported successfully as {export_format}")
except Exception as e:
st.error(f"Error: {e}")
if __name__ == "__main__":
main()
|