2
birth_data.sort_values(by='name',ascending = True) 
  • name numbers
    1. bruh 96570
    2. gib 95095
    3. mel 115195
    4. nish 112055
    5. raw 88018

I can sort the "numbers" but if i replace it with "name" I receive an error.

KeyError                                  Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2441             try:
-> 2442                 return self._engine.get_loc(key)
   2443             except KeyError:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'name'

During handling of the above exception, another exception occurred:
1
  • 1
    It means there are no column name, what is print (df.columns.tolist()) ? Commented Feb 21, 2018 at 9:47

1 Answer 1

2

Try that:

birth_data.sort_values(by=['name'], ascending = True)

Edit: Are you sure there is a column called 'name'?

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

2 Comments

by parameter can be a string or list of strings.
You are right. I think that the problem is the dataframe don't have a "name" column.

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.