gsa
gsa

Reputation: 800

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 though it works for other types? while read_table works for anything? and if they're the same while they exist?

Upvotes: 17

Views: 9522

Answers (3)

Ayşe Nur
Ayşe Nur

Reputation: 531

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().

Upvotes: 5

timgeb
timgeb

Reputation: 78650

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 pd                                                                                                

params_csv = inspect.signature(pd.read_csv).parameters                                                                
params_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'">)}

Upvotes: 2

EdChum
EdChum

Reputation: 393933

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

Upvotes: 18

Related Questions