1.set_index DataFrame可以通过set_index方法,可以设置单索引和复合索引. DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False) append添加新索引,drop为False,inplace为True时,索引将会还原为列 In [307]: data Out[307]: a b c d 0 bar one z 1.0 1 bar two y 2.…
一 set_index()函数 1 主要是理解drop和append参数,注意与reset_index()参数的不同. import pandas as pd df = pd.DataFrame({'a': range(4), 'b': range(4, 0, -1), 'c': ['one', 'one', 'two', 'two'], 'd': ['a','b','c','d']}) print(df) # a b c d # 0 0 4 one a # 1 1 3 one b # 2 2…