我想显示没有索引列的此 Dataframe 。我正在使用制表模块来更好地可视化数据,但不想在此处看到索引。我尝试在dftabulate中使用index=False,但它不接受此参数。
import pandas as pd
from tabulate import tabulate
# initialize list of lists
states = [['Alabama - AL', 'Alaska - AK', 'Arizona - AZ', 'Arkansas - AR', 'California - CA'],
['Colorado - CO', 'Connecticut - CT', 'Delaware - DE', 'Florida - FL', 'Georgia - GA'],
['Hawaii - HI', 'Idaho - ID', 'Illinois - IL', 'Indiana - IN', 'Iowa - IA'],
['Kansas - KS', 'Kentucky - KY', 'Louisiana - LA', 'Maine - ME', 'Maryland - MD'],
['Massachusetts - MA', 'Michigan - MI', 'Minnesota - MN', 'Mississippi - MS', 'Missouri - MO'],
['Montana - MT', 'Nebraska - NE', 'Nevada - NV', 'New Hampshire - NH', 'New Jersey - NJ'],
['New Mexico - NM', 'New York - NY', 'North Carolina - NC', 'North Dakota - ND', 'Ohio - OH'],
['Oklahoma - OK', 'Oregon - OR', 'Pennsylvania - PA', 'Rhode Island - RI', 'South Carolina - SC'],
['South Dakota - SD', 'Tennessee - TN', 'Texas - TX', 'Utah - UT', 'Vermont - VT'],
['Virginia - VA', 'Washington - WA', 'West Virginia - WV', 'Wisconsin - WI', 'Wyoming - WY']]
# Create the pandas DataFrame
df = pd.DataFrame(states, columns=['State - Abbreviation', 'State - Abbreviation', 'State - Abbreviation', 'State - Abbreviation', 'State - Abbreviation'])
pdtabulate = lambda df: tabulate(df, headers='keys', tablefmt='psql')
# print dataframe.
print(pdtabulate(df))
4条答案
按热度按时间bgibtngc1#
使用
tabulate
showindex = False
:inn6fuwd2#
仅用于显示:
另一个与输出类似的选项(使用Markdown语法):
8nuwlpux3#
你不能有没有索引的 Dataframe ,但没有索引打印漂亮,像excel工作表:
ogq8wdun4#
对于colab中的输出,您可以使用
HTML
实现相同的效果: