pandas reading csv orientation

前端 未结 2 2099
谎友^
谎友^ 2021-02-15 04:47

Hei I\'m trying to read in pandas the csv file you can download from here (euribor rates I think you can imagine the reason I would like to have this file!). The file is a CSV f

2条回答
  •  粉色の甜心
    2021-02-15 05:02

    A pandas dataframe has a .transpose() method, but it doesn't like all the empty rows in this file. Here's how to get it cleaned up:

    df = pandas.read_csv("hist_EURIBOR_2012.csv")  # Read the file
    df = df[:15]    # Chop off the empty rows beyond 12m
    df2 = df.transpose()
    df2 = df2[:88]  # Chop off what were empty columns (I guess you should increase 88 as more data is added.
    

    Of course, you can chain these together:

    df2 = pandas.read_csv("hist_EURIBOR_2012.csv")[:15].transpose()[:88]
    

    Then df2['3m'] is the data you want, but the dates are still stored as strings. I'm not quite sure how to convert it to a DateIndex.

提交回复
热议问题