Error while using pandas methods(sql business analysis project)

can someone help me figure out the following error?

AttributeErrorTraceback (most recent call last)
in ()
----> 1 employee_sales.set_index(“employee”, drop=True, inplace=True)
2 employee_sales.sort_values(‘total_sales’,inplace = True)
3 employee_sales.plot.barh(legend = False,
4 title = ‘Sales Breakdown by employee’,
5 colormap =

AttributeError: ‘str’ object has no attribute ‘set_index’

This error indicates that employee_sales is actually a string and not a pandas dataframe. To help explain why, let me provide the error and then a translation:


AttributeError: ‘str’ object has no attribute ‘set_index’


You tried to do something.set_index() but something is a str, and str objects doesn’t have a .set_index() method.

You can then look at the arrow (---->) in the traceback to see what line the error is talking about to understand that it’s talking about theemployee_sales variable.

I hope this is helpful!

would converting them using astype method do the trick?

In this case, it’s not a pandas object of string dtype, it’s an actual string, which means it doesn’t have the astype() method either!

To be able to resolve this issue, you’ll need to look at where you define (or perhaps redefine) employee_sales to understand why it’s a string instead of a pandas object.

Issue resolved