Skip to content Skip to sidebar Skip to footer

Is There A Difference Between Read_table And Read_csv In Pandas?

I've tested it and also checked the documentation with no visible differences.Either way i wanted to ask just in case. Do you think that read_csv should be used only for csv's even

Solution 1:

You can get either to work for general delimited files, the difference are the default params, for instance sep is '\t' (tab) for read_table but ',' for read_csv. They're both implemented the same underneath

If you look at the source

they call the same function with different separators:

read_csv = _make_parser_function('read_csv', sep=',')
read_csv = Appender(_read_csv_doc)(read_csv)

read_table = _make_parser_function('read_table', sep='\t')
read_table = Appender(_read_table_doc)(read_table)

and _make_parser_function:

def_make_parser_function(name, sep=','):

is a general method which accepts the sep arg

Solution 2:

Edit:Upon discussion, it was decided to keep the read_table, so this function is now undeprecated.

If you check out ~~ the Pandas documentation for read_table:

Deprecated since version 0.24.0.

Use pandas.read_csv() instead, passing sep='\t' if necessary.

So it is advised not to use read_table().

Solution 3:

The only difference is in fact the default value for the sep argument.

read_csv uses sep=',', read_table uses sep='\t' and that's it.

We can confirm this with the help of the inspect module by getting the signature parameters as ordered mappings.

import inspect                                                                                                     
import pandas as pdparams_csv= inspect.signature(pd.read_csv).parametersparams_table= inspect.signature(pd.read_table).parameters

There are only two elements in the symmetric difference of the parameters which both correspond to the sep argument and its different default value for the two functions.

>>> params_csv.items() ^ params_table.items()                                                                                
{('sep', <Parameter "sep=','">), ('sep', <Parameter "sep='\t'">)}

Post a Comment for "Is There A Difference Between Read_table And Read_csv In Pandas?"