-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79ddab3
commit de86b45
Showing
1 changed file
with
15 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
from pandas import read_csv, read_excel, read_json | ||
|
||
|
||
def createDf(requestFiles): | ||
if "file" not in requestFiles or not requestFiles["file"]: | ||
return False,"No file uploaded" | ||
file=requestFiles["file"] | ||
return False, "No file uploaded" | ||
file = requestFiles["file"] | ||
|
||
if (file.filename.endswith(".csv")): | ||
df = read_csv(file,dtype=str) | ||
elif (file.filename.endswith(".xlsx") or file.filename.endswith(".xls")): | ||
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) | ||
if file.filename.endswith(".csv"): | ||
df = read_csv(file, dtype=str) | ||
elif file.filename.endswith(".xlsx") or file.filename.endswith(".xls"): | ||
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, encoding="utf-8-sig") | ||
else: | ||
return False,"Please upload valid file format" | ||
return False, "Please upload valid file format" | ||
|
||
df = df.map(lambda x: x.strip() if isinstance(x,str) else "") | ||
df = df.map(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 | ||
return False, "Empty file uploaded" | ||
return True, df |