[英]Display pandas dataframe without index
I want to display this dataframe without the index column.我想在没有索引列的情况下显示此数据框。 i am using tabulate module to better visualize the data, but don't want to see the index here.
我正在使用制表模块来更好地可视化数据,但不想在这里看到索引。 i tried index=False in dftabulate, but it doesn't accept this argument.
我在 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))
I want to display this dataframe without the index column.我想显示不带索引列的该数据框。 i am using tabulate module to better visualize the data, but don't want to see the index here.
我正在使用制表模块以更好地可视化数据,但不想在这里看到索引。 i tried index=False in dftabulate, but it doesn't accept this argument.
我在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))
I want to display this dataframe without the index column.我想显示不带索引列的该数据框。 i am using tabulate module to better visualize the data, but don't want to see the index here.
我正在使用制表模块以更好地可视化数据,但不想在这里看到索引。 i tried index=False in dftabulate, but it doesn't accept this argument.
我在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))
I want to display this dataframe without the index column.我想显示不带索引列的该数据框。 i am using tabulate module to better visualize the data, but don't want to see the index here.
我正在使用制表模块以更好地可视化数据,但不想在这里看到索引。 i tried index=False in dftabulate, but it doesn't accept this argument.
我在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))
For output in colab you can achieve the same with HTML
:对于 colab 中的输出,您可以使用
HTML
实现相同的效果:
from IPython.display import HTML
HTML(df.to_html(index=False))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.