In [39]:
import pandas as pd
df = pd.read_csv("W1.csv")
df
Out[39]:
In [10]:
df.set_index(keys=["OrderID","customerID"]).sort_index()
Out[10]:
Works a little like groupby()¶
In [29]:
x = df.groupby(["OrderID","customerID"])
x.size()
Out[29]:
In [12]:
df.set_index(keys=["OrderID","customerID"]).index
Out[12]:
In [17]:
df.set_index(keys=["OrderID","customerID"]).index.names
Out[17]:
index_col on dataframe level is the same as .set_index()¶
In [32]:
import pandas as pd
df = pd.read_csv("W1.csv", index_col=("OrderID","customerID"))
df
Out[32]:
In [ ]:
No comments:
Post a Comment