示例#1
0
 def test_project_kwargs2(self):
     df = create_df()
     w = Wrap(df)
     wnew = w.project("A", **{"Z_col": "B * 2"})
     self.assertListEqual(["A", "Z_col"], list(wnew.df.columns))
     self.assertListEqual([0, 2, 4, 6, 8], list(wnew.df["Z_col"]))
     self.assertGreater(len(w.df.columns), 2)
示例#2
0
    def test_extract2(self):
        df = pd.DataFrame()
        df["A"] = ["Duration = 1;A, Duration=2;B", "Duration=3;C"]

        w = Wrap(df)
        wnew = w.project("D=extract('uration *= *([0-9]+);([^,]*)', 2, A)")
        self.assertListEqual(["D"], list(wnew.df.columns))
        self.assertListEqual(list(wnew.df["D"]), ["A", "C"])
示例#3
0
 def test_project(self):
     df = create_df()
     self.assertGreater(len(df.columns), 2)
     print(df.columns)
     w = Wrap(df)
     wnew = w.project("A", "B")
     self.assertListEqual(["A", "B"], list(wnew.df.columns))
     self.assertGreater(len(w.df.columns), 2)
示例#4
0
    def test_todatetime_column(self):
        df = create_df()
        df["D"] = pd.to_datetime(["2009-01-01", "2009-01-02", "2009-01-05", "2009-01-06", "2009-01-07"])    
        df["D1"] = ["2009-01-01", "2009-01-02", "2009-01-05", "2009-01-06", "2009-01-07"]   

        self.assertGreater(len(df.columns), 2)
        print(df.columns)
        w = Wrap(df)
        wnew = w.project("D", "DT1= todatetime(D1)")
        self.assertListEqual(["D", "DT1"], list(wnew.df.columns))
        self.assertListEqual(list(wnew.df["D"]), list(wnew.df["DT1"]))
示例#5
0
    def test_join(self):
        df = create_df()
        df2 = create_df()
        df2["B"] = [1, 0, -1, -1, -1]

        w = Wrap(df)
        w2 = Wrap(df2)

        wnew = w.join(w2.project("B", "C"), on="B")

        print(wnew.df)

        self.assertListEqual([0, 1], list(wnew.df["B"]))
        self.assertListEqual(["foo1", "foo2"], list(wnew.df["C"]))
        self.assertListEqual(["foo2", "foo1"], list(wnew.df["C_y"]))