-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_cutting.py
More file actions
36 lines (33 loc) · 1.2 KB
/
csv_cutting.py
File metadata and controls
36 lines (33 loc) · 1.2 KB
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
import pandas as pd
import streamlit as st
import shutil
from pathlib import Path
import zipfile
def ToCsvFiles(df, name):
rows_per_file = 100000
if len(df) < rows_per_file:
df.to_csv(f'results/{name}.csv', index=False, encoding='utf8')
st.write(f'Created {name}.csv')
else:
file_count = 1
for group_idx in range(0, len(df), rows_per_file):
df_subset = df.iloc[group_idx:group_idx+rows_per_file]
df_subset.to_csv(f'results/{name}_{file_count:02}.csv', index=False, encoding='utf8')
st.write(f'Created {name}_{file_count:02}.csv')
file_count += 1
name = st.text_input("Result files prefix", "result")
st.write("The current prefix is", name)
file_csv = st.file_uploader("Upload a csv", type=([".csv"]))
if file_csv is not None:
df = pd.read_csv(file_csv)
Path("results").mkdir(parents=True, exist_ok=True)
ToCsvFiles(df,name)
shutil.make_archive(name, 'zip', 'results')
with open(name + ".zip", "rb") as fp:
st.download_button(
label="Download results",
data=fp,
file_name=name + ".zip",
mime="application/zip",
icon=":material/download:",
)