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.

Satyajit Barik
  • 145
  • 1
  • 1
  • 8

2 Answers2

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.

AdamMcKay
  • 549
  • 6
  • 15
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'

Satyajit Barik
  • 145
  • 1
  • 1
  • 8