Print the DataFrame without index by using pandas module in Python
In this, Tutorial we will see how to print the DataFrame without index by using pandas in Python.
Steps :
1.) First import the pandas module as pd
import pandas as pd
2.) Now take any random csv file and add the address. we can read the csv file by using read_csv
command in pandas and store it in the variable in df.
df = pd.read_csv("#enter the path")
3.) Now we have to use the .to_string(index=False)
code : print(df.to_string(index=False))
When we print the data contained in dat.csv
file is:
name age gender
0 A M 60
1 B F 65
2 C F 20
3 D M 25
import pandas as pd df = pd.read_csv("C:\\Users\\appar\\OneDrive\\Desktop\\dat.csv") print(df.to_string(index=False))
Output:
name age gender
A M 60
B F 65
C F 20
D M 25
So like this, we can remove the index in the output while printing the dataset.
Leave a Reply