美文网首页Python
pandas读取数据之read_table()

pandas读取数据之read_table()

作者: 快乐自由拉菲犬 | 来源:发表于2019-04-17 13:40 被阅读257次
    1. pandas read_table

    pandas中读取表格的通用函数:read_table
    read_table()读取以‘/t’分割的文件到DataFrame
    read_table如何读取csv文件?


    2.在缺省分隔符的时候,依然可以读出数据:

    (摘自:https://www.jb51.net/article/143164.htm)


    3. pandas中read_table的参数
                  pandas.read_table(filepath_or_buffer,sep='\t',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,
                  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,escapechar=None,comment=None,encoding=None,dialect=None,
                  tupleize_cols=None,error_bad_lines=True,warn_bad_lines=True,skipfooter=0,
                  doublequote=True,delim_whitespace=False,low_memory=True,memory_map=False,
                  float_precision=None)
    

    4.如果文本中的分割符既有空格又有制表符(‘/t’),sep参数用‘/s+’,可以匹配任何空格。 代码如下:
    import pandas as pd
    df_txt = pd.read_csv('BSEP_NMC_ATME_SOB_EAQI_ACHN_LNO_P9_20160101060000000.TXT',sep='\s+')
    print df_txt
    

    5.为行和列添加索引

    用参数names添加列索引,用index_col添加行索引

    import pandas as pd
    df_txt = pd.read_csv('BSEP_NMC_ATME_SOB_EAQI_ACHN_LNO_P9_20160101060000000.TXT',sep='\s+',
                     names=['1','2','3','4','5','6','7','8','9','10','11'],index_col=0,header=1)
    print df_txt
    

    6.去掉diamond那一行,用header来操作
    import pandas as pd
    df_txt = pd.read_csv('BSEP_NMC_ATME_SOB_EAQI_ACHN_LNO_P9_20160101060000000.TXT',sep='\s+',
                     names=['1','2','3','4','5','6','7','8','9','10','11'],index_col=0,header=1)
     print df_txt
    

    (摘自:https://blog.csdn.net/shener_m/article/details/81047669

    相关文章

      网友评论

        本文标题:pandas读取数据之read_table()

        本文链接:https://www.haomeiwen.com/subject/peagwqtx.html