Skip to content

Commit

Permalink
Added JSON file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Sep 2, 2024
1 parent 44dfc70 commit f582af7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils/createDf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pandas import read_csv, read_excel
from pandas import read_csv, read_excel,read_json

def createDf(requestFiles):
if "file" not in requestFiles or not requestFiles["file"]:
Expand All @@ -11,12 +11,14 @@ def createDf(requestFiles):
df = read_excel(file,dtype=str)
elif (file.filename.endswith(".ods")):
df = read_excel(file,engine="odf",dtype=str)
elif file.filename.endswith(".json"):
df = read_json(file, dtype=str)
else:
return False,"Please upload valid file format"

df = df.applymap(lambda x: x.strip() if isinstance(x,str) else "")
df = df.loc[~(df == "").all(axis=1)]

if not len(df):
return False,"Empty file uploaded"
return True,df

0 comments on commit f582af7

Please sign in to comment.