2

I'm getting the following error from the code below:

***File "<ipython-input-61-517e344a129d>", line 1
    df.sort_values(by "Script Count", "Drug Name"), axis=0, ascending=True, inplace=False, kind='quicksort',
                                   ^
SyntaxError: invalid syntax*** (the carrot is pointing to the second " following "Script Count")

Code:

import pandas as pd

import numpy as np

df = pd.read_csv('/Users/rmartin/Desktop/DE_Highmark.csv')

df.sort_values(by "Script Count", "Drug Name"), axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')

I know this must be super simple, but I've driven myself crazy trying to figure it out. I'm trying to sort the dataframe based on the "Script Count" and "Drug Name" columns from a dataframe. The CSV was successfully imported as a dataframe, but the sort function is giving me trouble.

1
  • 5
    Try df.sort_values(by = [ "Script Count", "Drug Name"], axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last') Commented May 30, 2017 at 19:32

1 Answer 1

2

Refering to the docs, the right syntax is:

 DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')

so in your case, it should be:

df.sort_values(by=[ "Script Count", "Drug Name"], ascending=[True,True]) 
Sign up to request clarification or add additional context in comments.

1 Comment

Let's get the current version docs. pandas.pydata.org/pandas-docs/stable/generated/…

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.