📜  pandas print dataframe without index - Python (1)

📅  最后修改于: 2023-12-03 15:18:14.016000             🧑  作者: Mango

Pandas Print Dataframe Without Index - Python

Sometimes it's useful to be able to print a dataframe without the index. This can be useful when dealing with large dataframes where the index is not relevant, or when you simply want to save space in your output.

Here's how to print a pandas dataframe without the index:

import pandas as pd

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

print(df.to_string(index=False))

This will print the dataframe without the index:

 A  B
 1  4
 2  5
 3  6

Alternatively, you can set the index to a blank string before printing the dataframe:

import pandas as pd

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

df.index = ''

print(df.to_string())

This will also print the dataframe without the index:

 A  B
 1  4
 2  5
 3  6

Using these methods, you can easily print a pandas dataframe without the index in a variety of different situations.