Pandas read_table() function



Pandas read_table() function

Pandas is one of the most used packages for analyzing data, data exploration, and manipulation. While analyzing the real-world data, we often use the URLs to perform different operations and pandas provide multiple methods to do so. One of those methods is read_table().

Parameters:
read_table(filepath_or_buffer, sep=False, delimiter=None, header=’infer’, names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, skipfooter=0, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, iterator=False, chunksize=None, compression=’infer’, thousands=None, decimal=b’.’, lineterminator=None, quotechar=’”‘, quoting=0, doublequote=True, escapechar=None, comment=None, encoding=None, dialect=None, tupleize_cols=None, error_bad_lines=True, warn_bad_lines=True, delim_whitespace=False, low_memory=True, memory_map=False, float_precision=None)

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.

Code #1: Display the whole content of the file with columns separated by ‘,’

# importing pandas
import pandas as pd
 
pd.read_table('nba.csv',delimiter=',')

Output:

 

 

Code #2: Skipping rows without indexing

# 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.

Code #3: Skipping rows with indexing

# importing pandas
import pandas as pd
 
pd.read_table('nba.csv',delimiter=',',skiprows=4)

Output:

Code #4: In case of large file, if you want to read only few lines then give required number of lines to nrows.

# importing pandas
import pandas as pd
 
pd.read_table('nba.csv',delimiter=',',index_col=0,nrows=4)

Output:

Code #5: If you want to skip lines from bottom of file then give required number of lines to skipfooter.

# importing pandas
import pandas as pd
 
pd.read_table('nba.csv',delimiter=',',index_col=0,
                     engine='python',skipfooter=5)

Output:

Code #6: Row number(s) to use as the column names, and the start of the data occurs after the last row number given in header.

# importing pandas
import pandas as pd
 
pd.read_table('nba.csv',delimiter=',',index_col=0,header=[1,3,5])

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

Last Updated on October 19, 2021 by admin

Leave a Reply

Your email address will not be published. Required fields are marked *

Recommended Blogs