Is there a difference between read_table and read_csv in pandas?

前端 未结 3 1245
太阳男子
太阳男子 2021-02-13 11:59

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 fo

相关标签:
3条回答
  • 2021-02-13 12:42

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

    0 讨论(0)
  • 2021-02-13 12:43

    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'">)}
    
    0 讨论(0)
  • 2021-02-13 12:50

    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

    0 讨论(0)
提交回复
热议问题