Pandas read_table() function
Last Updated :
14 Dec, 2023
Pandas is one of the most used packages for analyzing data, data exploration, and manipulation. While analyzing real-world data, we often use the URLs to perform different operations and Pandas provide multiple methods to read tabular data in Pandas. One of those methods is read_table()
Pandas read_table() Function Syntax
Below is the syntax of pandas.read_table() function.
Syntax: pandas.read_table(filepath_or_buffer, delimiter=None, header='infer', names=None, index_col=None, usecols=None, dtype=None, skiprows=None, na_values=None, parse_dates=False, encoding=None, comment=None)
Parameters:
f
ilepath_or_buffer
: The path or object representing a file to be read.delimiter
: The delimiter to use, in this case, it's retained for specifying the column separator.header
: Row(s) to use as the column names.names
: List of column names to use.index_col
: Column(s) to set as index (can be a single column name or a list of names).usecols
: Columns to read from the file.dtype
: Data type to force.skiprows
: Number of rows to skip at the beginning of the file.na_values
: Additional strings to recognize as NA/NaN.
Returns: A comma(',') separated values file(csv) is returned as two dimensional data with labelled axes.
To get the link to csv file used in the article, click here.
Python Pandas read_table() Function Examples
Below are some examples of Pandas read_table() function in Python:
Example 1: Pandas Read CSV into DataFrame
Display the whole content of the file with columns separated by ','. In this example, the code utilizes the pandas library to read data from a CSV file named 'nba.csv' using the pd.read_table
function with a comma (,
) as the specified delimiter. The resulting DataFrame is not assigned to a variable for further manipulation. Here, we will read tabular data in pandas by using read_table().
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',')
Output:

Example 2: Skipping rows Without Indexing Using read_table() Function
In this example, the code employs the pandas library to read data from a CSV file ('nba.csv') using pd.read_table
, specifying a comma (,
) as the delimiter. It skips the first 4 rows and designates the values in the first column as the DataFrame index and we will read tabular data in pandas.
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',', skiprows=4, index_col=0)
Output:

In the above code, four rows are skipped and the last skipped row is displayed.
Example 3: Skipping Rows With Indexing in Pandas
In this example, the code utilizes pandas to read tabular data in Pandas from the 'nba.csv' file with a comma (,
) as the delimiter. It skips the first 4 rows, creating a DataFrame with the remaining data.
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',', skiprows=4)
Output:

Example 4: Read Specific Rows Using read_table()
In case of large file, if you want to read only few lines then give required number of lines to nrows. In this example, the code employs pandas to read the first 4 rows from the 'nba.csv' file, using a comma (,
) as the delimiter. It designates the values in the first column as the DataFrame index.
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',', index_col=0, nrows=4)
Output:

Example 5: Skipping Lines from Bottom of File
If you want to skip lines from bottom of file then give required number of lines to skipfooter. In this example, the code uses pandas to read data from 'nba.csv', specifying a comma (,
) as the delimiter. It sets the values in the first column as the DataFrame index, employs the Python engine, and skips the last 5 rows during the file reading process.
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',', index_col=0,
engine='python', skipfooter=5)
Output:

Example 6: Multi-Level Indexing with Pandas
Row number(s) to use as the column names, and the start of the data occurs after the last row number given in header.
Python3
# importing pandas
import pandas as pd
pd.read_table('nba.csv', delimiter=',', index_col=0, header=[1, 3, 5])
Output:
Similar Reads
How to Read Text Files with Pandas? In this article, we will discuss how to read text files with pandas in Python. In Python, the Pandas module allows us to load DataFrames from external files and work on them. The dataset can be in different types of files.Text File UsedRead Text Files with PandasBelow are the methods by which we can
6 min read
How to Read JSON Files with Pandas? JSON (JavaScript Object Notation) store data using key-value pairs. Reading JSON files using Pandas is simple and helpful when you're working with data in .json format. There are mainly three methods to read Json file using Pandas Some of them are:Using pd.read_json() MethodUsing JSON Module and pd.
2 min read
pandas.array() function in Python This method is used to create an array from a sequence in desired data type. Syntax : pandas.array(data: Sequence[object], dtype: Union[str, numpy.dtype, pandas.core.dtypes.base.ExtensionDtype, NoneType] = None, copy: bool = True) Parameters : data : Sequence of objects. The scalars inside `data` sh
2 min read
Pandas Read CSV in Python CSV files are the Comma Separated Files. It allows users to load tabular data into a DataFrame, which is a powerful structure for data manipulation and analysis. To access data from the CSV file, we require a function read_csv() from Pandas that retrieves data in the form of the data frame. Hereâs a
6 min read
Reading rpt files with Pandas In most cases, we usually have a CSV file to load the data from, but there are other formats such as JSON, rpt, TSV, etc. that can be used to store data. Pandas provide us with the utility to load data from them. In this article, we'll see how we can load data from an rpt file with the use of Pandas
2 min read