Python 3.x 如何隐藏熊猫和Jupyter的索引0
我想从我的jupyter笔记本中隐藏de索引0(行):Python 3.x 如何隐藏熊猫和Jupyter的索引0,python-3.x,pandas,jupyter-notebook,Python 3.x,Pandas,Jupyter Notebook,我想从我的jupyter笔记本中隐藏de索引0(行): display(df.style.set_properties(**{'text-align': 'left'}) 我使用的方法是style,以便将其作为html和左对齐, 其中df是一个简单的数据帧 谢谢大家! 你想要什么还不清楚。所以我要猜一猜 考虑数据帧df df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('ABC'), list('XY')) 正如@chtonicdaemon所指
display(df.style.set_properties(**{'text-align': 'left'})
我使用的方法是style,以便将其作为html和左对齐,
其中df是一个简单的数据帧
谢谢大家! 你想要什么还不清楚。所以我要猜一猜 考虑数据帧
df
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('ABC'), list('XY'))
正如@chtonicdaemon所指出的,简单地“隐藏”第一行非常容易:
df.iloc[1:]
X Y
B 3 4
C 5 6
我假设你想要不同的东西。我以前看到的问题是如何不显示索引?我将首先指出我先前的答案
这是我将用于应用自己的css
def HTML_with_style(df, style=None, random_id=None):
from IPython.display import HTML
import numpy as np
import re
df_html = df.to_html()
if random_id is None:
random_id = 'id%d' % np.random.choice(np.arange(1000000))
if style is None:
style = """
<style>
table#{random_id} {{color: blue}}
</style>
""".format(random_id=random_id)
else:
new_style = []
s = re.sub(r'</?style>', '', style).strip()
for line in s.split('\n'):
line = line.strip()
if not re.match(r'^table', line):
line = re.sub(r'^', 'table ', line)
new_style.append(line)
new_style = ['<style>'] + new_style + ['</style>']
style = re.sub(r'table(#\S+)?', 'table#%s' % random_id, '\n'.join(new_style))
df_html = re.sub(r'<table', r'<table id=%s ' % random_id, df_html)
return HTML(style + df_html)
这不适用于
打印(df)
有什么原因不能在没有带df.loc[1://code>的第一行的情况下显示数据帧?
style = """
<style>
table tr :first-child{display: none;}
</style>
"""
HTML_with_style(df, style)