Mar-02-2023, 09:29 AM
Hello everyone,
Please I need advice from you. I trying read csv file using Pandas in Django. I need read whole file and also need read (find) on first line specific word. I tried read file twice, but I got error "No columns to parse from file".
This is my code:
Please I need advice from you. I trying read csv file using Pandas in Django. I need read whole file and also need read (find) on first line specific word. I tried read file twice, but I got error "No columns to parse from file".
This is my code:
def csv(request): if request.method == "POST" and 'myFile' in request.FILES: file = request.FILES["myFile"] csv = pd.read_csv(file, skiprows=0, sep=";") firstLine = pd.read_csv(file, skiprows=0, sep=";", nrows=0) dict = { 'Unnamed: 0': "", 'Unnamed: 1': "", 'Unnamed: 2': "", 'Unnamed: 3': "", 'Unnamed: 4': "", 'Unnamed: 5': "", 'Unnamed: 6': "", 'Unnamed: 7': "", 'Unnamed: 8': "", } csv.rename(columns = dict, inplace = True) csv.fillna("", inplace=True) data = csv.to_html(index=False) return render(request, "index.html", {"dataLoaded": True, "data": data, "firstLine": firstLine }) else: return render(request, "index.html", {"message": "Something is wrong!"})Thank you for any help :)