如何将pandas DF分成不同的变量?

时间:2016-08-06 12:34:52

标签: python pandas numpy

这是来自here

的后续问题

我使用以下代码从网站上删除

soup = bs4.BeautifulSoup(driver.page_source, "html.parser")
    for thead in soup.select(".data-point-container table thead"):
        tbody = thead.find_next_sibling("tbody")

        table = "<table>%s</table>" % (str(thead) + str(tbody))

        df = pandas.read_html(str(table), header=0, index_col=0)[0]
        df = df.drop(['Unnamed: 6'], axis=1)

        # Renaming Columns to just have FY-YEAR
        for each_column in df.columns:
            if each_column[:3] == "LTM":
                df.rename(columns={each_column: "Last 12 Months"}, inplace=True)
            else:
                df.rename(columns={each_column: each_column[:6]}, inplace=True)

        df = df.T

        print(df)
        print("-------------------------------------")

执行时,会产生此结果。

capture 1

屏幕截图显示了2个数据帧,代码执行总共有6个数据帧。

我想要做的是将它们合并在一起,这样在行轴上,它只显示FY2012, FY2013, FY2014, FY2015, Last 12 Months,在列轴上,它将显示6 {{的所有行的组合。 1}}它从网站上删除了。

我认为我可以通过将其分成不同的Dataframe并使用variables方法的形式来实现此目的。但是我遇到了麻烦,首先将df.join()分成不同的变量..

你怎么看?

更新

最初我以为我可以做一个df,但这给了我一个print(df[0])

0 个答案:

没有答案
相关问题