1

I convert dictionaries to a DataFrame and change the index but I still get the numeric index numbers assigned by Pandas. Why didn't the index change to the name column?

import numpy as np
import pandas as pd

exam_scores = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19]}
scores = pd.DataFrame(exam_scores)
scores.set_index('name')
print(scores.describe)

<bound method NDFrame.describe of         name  score
0  Anastasia   12.5
1       Dima    9.0
2  Katherine   16.5
3      James    NaN
4      Emily    9.0
5    Michael   20.0
6    Matthew   14.5
7      Laura    NaN
8      Kevin    8.0
9      Jonas   19.0>
nicomp
  • 4,344
  • 4
  • 27
  • 60

1 Answers1

2

Set it inplace to make the reset_index permanent

import numpy as np
import pandas as pd

exam_scores = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19]}
scores = pd.DataFrame(exam_scores)
scores.set_index('name', inplace=True)
scores
wwnde
  • 26,119
  • 6
  • 18
  • 32