4. MultiIndex Flashcards

1
Q

setting up multi index

A

df.set_index([“Date”,”Country”])

df = pd.read_csv(“bigmac.csv”,parse_dates=[“Date”], index_col=[“Date”,”Country”])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

df.index

A

return tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

breakdown df.index

A

df.index.get_level_values(“Country”)-> return normal index vector
or
df.index.get_level_values(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

change index name

A

df.index.set_names([“Day”,”Location”], inplace=True)

df. index.set_names(“Date”, level = “Day”)
df. index.set_names(“Date”, level = 0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly