0

I'm getting AttributeError: 'list' object has no attribute 'sort_values' in below code,

task.py:

from __future__ import absolute_import,unicode_literals
from celery import shared_task
from time import sleep
import eda
import os

@shared_task
def aync_task(amz_columns_dict, download_path, file_name, data):
    sleep(10)
    eda_object = eda.eda(col_dict=amz_columns_dict)
    save_path = download_path
    name_of_file = file_name 
    file_path = os.path.join(save_path, name_of_file+".html")     
    eda_object.create_report(data=data, filename=file_path)
    return 'task complete'

views.py :

def eda_flow(request):
    path = '/Unilever/satyajit/us_amz.csv'
    mode = 'rb'
    df = pd.read_csv("/home/satyajit/Desktop/opensource/data/us_amz.csv", low_memory=False)
    df = df.head(100)
    json_records = df.reset_index().to_json(orient ='records')
    data = []
    data = json.loads(json_records)
    context = {'data': data, 'message': 'data loaded successfully.'}
    if request.method == 'POST':
        id_col = request.POST.get('id_col')
        file_name = request.POST.get('file_name')
        download_path = request.POST.get('download_path')
        amz_columns_dict = {'id_col': id_col}
        try:   
            if os.path.exists(download_path):
                status = aync_task.delay(amz_columns_dict, download_path, file_name, data)
                return render(request,'home/index.html', {'message': 'Save Complete'})
            else:
                return render(request,'home/index.html', {'message': 'download path is not exist'})
        except Exception as e:
            print('error is---->', e)
            return render(request,'home/index.html', {'message': 'Error while generating EDA'})
    return render(request, "home/tables-simple.html", context)

The error of this code on below as screenshot:

enter image description here

I've also tried to search similar question here (similar question) but that does not helpful to me.

Any help would be much appreciated. thanks in advance.

2
  • Have you done, import pandas as pd then data = pd.DataFrame(data) to convert the python list to a pandas DataFrame? Commented Oct 30, 2022 at 15:31
  • @raphael yes, i have done that Commented Oct 30, 2022 at 15:32

2 Answers 2

0

Your data variable that is being passed to the async_task method is being set using data = json.loads(json_records) so it's a normal Python list. You must convert this to a Pandas dataframe before using it with eda_object.create_report.

Sign up to request clarification or add additional context in comments.

1 Comment

After i convert it to pandas dataframe then i'm getting this error Object of type DataFrame is not JSON serializable
0

this solved my issue:

task.py :

@shared_task
def aync_task(amz_columns_dict, download_path, file_name):
    sleep(10)
    df = pd.read_csv("/home/satyajit/Desktop/opensource/data/us_amz.csv", low_memory=False)
    df = df.head(3500)
    eda_object = eda.eda(col_dict=amz_columns_dict)
    save_path = download_path
    name_of_file = file_name
    # file_path = Path(save_path, name_of_file+".html")  
    file_path = os.path.join(save_path, name_of_file+".html")     
    eda_object.create_report(data=df, filename=file_path)
    return 'task complete'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.