Pandas 用系列中的值填充列
我有一个Pandas 用系列中的值填充列,pandas,Pandas,我有一个pandasgroupby().sum()的产品,如下所示: DTO ZONA 1 1 4839 2 7347 3 1945 4 2248 5 9395 99999 575 2 1 8739 2 7436 3 5528 4 7490 现在我
pandas
groupby().sum()
的产品,如下所示:
DTO ZONA
1 1 4839
2 7347
3 1945
4 2248
5 9395
99999 575
2 1 8739
2 7436
3 5528
4 7490
现在我想谈谈:
DTO ZONA
1 1 4839
1 2 7347
1 3 1945
1 4 2248
1 5 9395
1 99999 575
2 1 8739
2 2 7436
2 3 5528
2 4 7490
这肯定是以前问过的,但我缺乏搜索它的概念。这是一个
pandas
选项,它稀疏了pd.MultiIndex
。您可以使用名为display.multi\u sparse
的选项将其关闭。您可以看到其他选项
您可以使用
pd.options\u context
with pd.option_context('display.multi_sparse', False):
print(s)
DTO ZONA
1 1 4839
1 2 7347
1 3 1945
1 4 2248
1 5 9395
1 99999 575
2 1 8739
2 2 7436
2 3 5528
2 4 7490
dtype: int64
如果要永久设置该选项,请执行以下操作:
pd.set_option('display.multi_sparse', False)
非常简单:
df.reset_index(drop=True, inplace=True)
df.reset_index(drop=True, inplace=True)