Pandas read in table without headers

Solution for "Pandas read in table without headers". By Pranit Sharma Last updated : September 19, 2023

Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and the data. DataFrame can be created with the help of python dictionaries or lists but in the real world, CSV files are imported and then converted into DataFrames.

In a CSV file, headers are the values assigned to each column, it is an array of values and it acts as a row or headers. While reading a CSV file, we sometimes don't want the headers, in that case, we do not open the CSV file along with headers, below is the example explaining the implementation.

Let us understand with the help of an example:

Python program to read and print cvs file data

# Importing pandas package
import pandas as pd

# Importing dataset
data=pd.read_csv('D:/mycsv1.csv')

# Print the dataset
print(data)

Output

The output of the above program is:

Example 1: Read in table without headers

Read in table without headers

To read in table without headers, we will pass header = None as a parameter.

Python program to read in table without headers

# Importing pandas package
import pandas as pd

# Importing dataset
data=pd.read_csv('D:/mycsv1.csv', header=None)

# Print the dataset
print(data)

Output

The output of the above program is:

Example 2: Read in table without headers

Python Pandas Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.