How do I read a fix width format text file in pandas

后端 未结 4 1971
Happy的楠姐
Happy的楠姐 2020-12-07 01:16

I just got my hands on pandas and am figuring out how I can read a file. The file is from WRDS database and is the SP500 constituents list all the way back to 1960s. I check

4条回答
  •  失恋的感觉
    2020-12-07 01:29

    What do you mean by display? Doesn't df['gvkey'] give you the data in the gvkey column?

    If what you do is print the whole data frame to the console, then take a look at df.to_string(), but it'll be hard to read if you have too many columns. Pandas won't print the whole thing by default if you have too many columns:

    import pandas
    import numpy 
    
    df1 = pandas.DataFrame(numpy.random.randn(10, 3), columns=['col%d' % d for d in range(3)] )
    df2 = pandas.DataFrame(numpy.random.randn(10, 30), columns=['col%d' % d for d in range(30)] )
    
    print df1   # <--- substitute by df2 to see the difference
    print
    print df1['col1']
    print
    print df1.to_string()
    

提交回复
热议问题