如何在不添加列和索引名称的情况下旋转数据框 [英] how to pivot dataframe without adding column and index name
本文介绍了如何在不添加列和索引名称的情况下旋转数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pivot是一个很棒的功能,但会导致一个数据框包含一些我不需要的额外信息:如何在下面实现?我不需要"bar"或"foo",并且我想使df更加简洁.谢谢.
pivot is a great function but results in a dataframe with a few extra info that I don't need: How can I achieve below? I do not need "bar" or "foo", and I want to make the df more concise. Thanks.
推荐答案
将index
和columns
名称设置为None
:
df.index.name = None
df.columns.name = None
或使用 rename_axis
:
df = df.rename_axis(None).df.rename_axis(None, axis=1)
这篇关于如何在不添加列和索引名称的情况下旋转数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文