Reindexing a Series
Reindexing is a technique for creating a brand-new Series from an existing one — the new Series has the same kind of labels, but arranged in the order you specify.
1Reorder the labels
reindex() takes a list of index labels and returns a new Series whose rows follow that exact order. Explore what happens when you reorder, reverse, or ask for a label that doesn't exist:
Reindexing builds a BRAND-NEW Series with the labels you ask for, in the order you ask for. Ask for a label that doesn't exist and its value is NaN.
Same values, new order — and s1 itself never changes. reindex() always returns a new Series.
2Reordering existing labels
Pass the labels in whatever order you want. The values travel with their labels, and the original Series is left untouched.
3Asking for a label that doesn't exist
If you list a label that isn't in the original Series, Pandas still creates that row — but it has no value to put there, so it fills it with NaN (which also makes the Series float64 if it was numeric).
fill_value=0 (or any value): marks.reindex(['a', 'z'], fill_value=0).reindex() always returns a new Series in the order you asked for. Labels that don't exist come back as NaN (or your fill_value).s has labels a, b, c. What does s.reindex(['c', 'a']) return?
You reindex a numeric Series with a label that doesn't exist. That row's value is…