The following method for uploading data to database (mongodb) works for CSV files but not for Excel files, despite using read_csv and read_excel respectively. I have also tried to fiddle with parameters for read_excel without any success.
The error I continue to receive is
FileNotFoundError: [Errno 2] No such file or directory: 'data2.xlsx'
The CSV and Excel file data are identical, except for the different file type.
@app.route('/<string:dbase>/fileupload', methods=['GET', 'POST'])
def file_upload(dbase):
mydb = client[dbase]
if request.method == 'POST':
file = request.form.get('fileupload')
split = os.path.splitext(file) # split[1] becomes file extension name e.g. '.xlsx' or '.csv'
if split[1] == '.xlsx' or split[1] == '.xls' or split[1] == '.xlsm' or split[1] == '.xlsb' or split[1] == '.ods':
df=pd.read_excel(file)
if split[1] == '.csv':
df=pd.read_csv(file)
accounts = df['Account'].tolist()
accs_to_add=[]
for acc in accounts:
accs_to_add.append(acc)
accs_to_add = list(set(accs_to_add))
for acc in accs_to_add:
accs_col.insert_one({'Account':acc})
return 'done'
else:
return render_template('file_upload.html', dbase=dbase)
Thanks for your help