def fetchQuotes(sym, start=FROM_DATE, end=CURRENT_DATE):
    his = None
    data = None
    try:
        # print start, end
        data = ystockquote.get_historical_prices(sym, start, end)
    except Exception:
        print "Please check the dates. Data might not be available. 404 returned"

        # 404 due to data yet not available
    if data:
        his = DataFrame(collections.OrderedDict(sorted(data.items()))).T
        his = his.convert_objects(convert_numeric=True)
        his.index = pd.to_datetime(his.index)
        his.insert(0, "symbol", sym, allow_duplicates=True)
        # insert the date as dataframe too
        his.insert(1, "date", his.index)
        # his.columns = getColumns('stock_quote_historical')   # Removing as db dependency is removed
        his.columns = getColumnsNoSql("stock_quote_historical")

    daily = ystockquote.get_all(sym)
    # print daily
    # persist(his, daily, sym, end)

    return his, daily
Example #2
0
    def test_fillna_columns(self):
        df = DataFrame(np.random.randn(10, 10))
        df.values[:, ::2] = np.nan

        result = df.fillna(method="ffill", axis=1)
        expected = df.T.fillna(method="pad").T
        assert_frame_equal(result, expected)

        df.insert(6, "foo", 5)
        result = df.fillna(method="ffill", axis=1)
        expected = df.astype(float).fillna(method="ffill", axis=1)
        assert_frame_equal(result, expected)
Example #3
0
    def test_mixed_type_join_with_suffix(self):
        # GH #916
        df = DataFrame(np.random.randn(20, 6), columns=["a", "b", "c", "d", "e", "f"])
        df.insert(0, "id", 0)
        df.insert(5, "dt", "foo")

        grouped = df.groupby("id")
        mn = grouped.mean()
        cn = grouped.count()

        # it works!
        mn.join(cn, rsuffix="_right")
    def test_insert(self):
        df = DataFrame(np.random.randn(5, 3), index=np.arange(5), columns=["c", "b", "a"])

        df.insert(0, "foo", df["a"])
        self.assert_numpy_array_equal(df.columns, ["foo", "c", "b", "a"])
        assert_almost_equal(df["a"], df["foo"])

        df.insert(2, "bar", df["c"])
        self.assert_numpy_array_equal(df.columns, ["foo", "c", "bar", "b", "a"])
        assert_almost_equal(df["c"], df["bar"])

        # diff dtype

        # new item
        df["x"] = df["a"].astype("float32")
        result = Series(dict(float64=5, float32=1))
        self.assertTrue((df.get_dtype_counts() == result).all())

        # replacing current (in different block)
        df["a"] = df["a"].astype("float32")
        result = Series(dict(float64=4, float32=2))
        self.assertTrue((df.get_dtype_counts() == result).all())

        df["y"] = df["a"].astype("int32")
        result = Series(dict(float64=4, float32=2, int32=1))
        self.assertTrue((df.get_dtype_counts() == result).all())

        with assertRaisesRegexp(ValueError, "already exists"):
            df.insert(1, "a", df["b"])
        self.assertRaises(ValueError, df.insert, 1, "c", df["b"])

        df.columns.name = "some_name"
        # preserve columns name field
        df.insert(0, "baz", df["c"])
        self.assertEqual(df.columns.name, "some_name")
Example #5
0
def file_prep(file):
    df = DataFrame(read_csv(file, sep="\t"))
    df.drop(df[df.apply(allele_count, axis=1) != 2].index, inplace=True)
    major_freqs = df.apply(major_prop_find, axis=1)
    major_alleles = df.apply(major_find, axis=1)
    df.insert(3, "major_freqs", major_freqs)
    df.insert(3, "major_alleles", major_alleles)
    df = df.transpose()

    chrom, chrom_idx = np.unique(df.loc["chrom"], return_index=True)

    super_missing_df = df == "."

    chromosome_dict = {}
    for number in np.unique(df.loc["chrom"]):
        chromosome_dict[number] = df.loc["chrom"][df.loc["chrom"] == number].index
    return df, super_missing_df, chromosome_dict
Example #6
0
    def test_insert_column_bug_4032(self):

        # GH4032, inserting a column and renaming causing errors
        df = DataFrame({"b": [1.1, 2.2]})
        df = df.rename(columns={})
        df.insert(0, "a", [1, 2])

        result = df.rename(columns={})
        str(result)
        expected = DataFrame([[1, 1.1], [2, 2.2]], columns=["a", "b"])
        assert_frame_equal(result, expected)
        df.insert(0, "c", [1.3, 2.3])

        result = df.rename(columns={})
        str(result)

        expected = DataFrame([[1.3, 1, 1.1], [2.3, 2, 2.2]], columns=["c", "a", "b"])
        assert_frame_equal(result, expected)
Example #7
0
def ingest(app, path=""):
    c = ConfigParser.ConfigParser()
    for f in "ref_perf.txt", "auto_perf.txt", "naive_perf.txt", "sweep_perf.txt":
        c.read(os.path.join(path, app, f))
    df = DataFrame([dict(c.items(s)) for s in c.sections()])

    # coerce types
    for col in df.columns:
        try:
            ints = df[col].astype(int)
            df[col] = ints
        except:
            try:
                floats = df[col].astype(float)
                df[col] = floats
            except:
                pass  # keep as string

    # coerce old data names if present
    df = df.rename(columns={"nthreads": "threads"})

    app_name = app.replace("_", " ").title()

    df.insert(0, "app", app)
    df.insert(0, "app_name_pretty", app_name)
    assert len(df)
    df["throughput"] = 1000.0 / df.runtime  # runs/sec
    df["speedup"] = 0.0

    # this is a little bullshit, but DataFrame slice indexing gets confusing
    ref = df[df.version == "ref"]  # .set_index('threads')

    def compute_speedup(row):
        r = ref[ref.threads == row.threads].runtime.iloc[0]  # FFFfffuuu
        row.speedup = r / row.runtime
        return row

    df = df.apply(compute_speedup, axis=1)

    df["runtime_norm"] = df.runtime / max(df.runtime)
    df["throughput_norm"] = df.throughput / max(df.throughput)

    return df
Example #8
0
def average_by_cell_line():
    datasets = load_datasets()
    ess_train_data = datasets["ess_train_data"]

    lines_board = load_cell_lines(CELL_LINES_LEADERBOARD_PH1)
    lines_train = load_cell_lines(CELL_LINES_TRAINING_PH1)

    data = {}

    for line in lines_board.index:
        site = lines_board.at[line, "Site_primary"]
        matches = lines_train.index[lines_train["Site_primary"] == site]
        if matches.size > 0:
            data[line] = ess_train_data.loc[:, matches].mean(1).tolist()
        else:
            data[line] = ess_train_data.mean(1).tolist()

    ess_avg_data = DataFrame(data, index=ess_train_data.index, columns=lines_board.index)
    ess_avg_data.insert(0, "Description", ess_train_data.index)
    save_gct_data(ess_avg_data, "avg_per_line.gct")
Example #9
0
class InfoTable(DataFrameWidget):
    def __init__(self, samples=None):
        self.initVars()
        super(InfoTable, self).__init__(self.table)

    def initVars(self):
        """Initialises variables."""
        self.columns = ["Plate ID", "Plate Name", "Plate Kea", "Well"]
        self.table = DataFrame(columns=self.columns)

    ########################################################################
    def update(self):
        plateID = self.table["Plate ID"]
        plateName = self.table["Plate Name"]
        plateKea = self.table["Plate Kea"]
        well = self.table["Well"]
        self.table = self.table.drop(labels=["Plate ID", "Plate Name", "Plate Kea", "Well"], axis=1)
        self.table.insert(0, "Plate ID", plateID)
        self.table.insert(1, "Plate Name", plateName)
        self.table.insert(2, "Plate Kea", plateKea)
        self.table.insert(3, "Well", well)
        self.setDataFrame(self.table)

    def append(self, appendage):
        self.table = self.table.append(appendage, ignore_index=True)
        self.update()

    def editPlates(self, edits):
        self.table = self.table.set_index("Plate ID")
        edits = edits.set_index("ID")
        self.table.update(edits)
        self.table = self.table.reset_index()

    def importPlateData(self, plateData, key):
        plateData = plateData.set_index(key)
        self.table = self.table.set_index(key)
        self.table.update(plateData)
        self.table = self.table.reset_index()

    def importSampleData(self, sampleData, tableKey, importKey):
        sampleData[tableKey] = sampleData[importKey]
        sampleData = sampleData.set_index(tableKey)
        self.table = self.table.set_index(tableKey)
        self.table = self.table.join(sampleData, rsuffix="_new")
        self.table = self.table.reset_index()

    def getKeaSexTestingData(self):
        table = self.table[["Plate ID", "Well", "Sample ID", "Plant Alt Names"]]
        table = table.set_index(["Plate ID", "Well"])
        table.rename(columns={"Plant Alt Names": "Plant AltName"}, inplace=True)
        return table
Example #10
0
def getNgrams(query, corpus, startYear, endYear, smoothing, caseInsensitive):
    params = dict(
        content=query,
        year_start=startYear,
        year_end=endYear,
        corpus=corpora[corpus],
        smoothing=smoothing,
        case_insensitive=caseInsensitive,
    )
    if params["case_insensitive"] is False:
        params.pop("case_insensitive")
    if "?" in params["content"]:
        params["content"] = params["content"].replace("?", "*")
    if "@" in params["content"]:
        params["content"] = params["content"].replace("@", "=>")
    req = requests.get("http://books.google.com/ngrams/graph", params=params)
    res = re.findall("var data = (.*?);\\n", req.text)
    data = {qry["ngram"]: qry["timeseries"] for qry in literal_eval(res[0])}
    df = DataFrame(data)
    df.insert(0, "year", range(startYear, endYear + 1))
    return req.url, params["content"], df
Example #11
0
    def test_insert(self):
        df = DataFrame(np.random.randn(5, 3), index=np.arange(5), columns=["c", "b", "a"])

        df.insert(0, "foo", df["a"])
        self.assert_index_equal(df.columns, Index(["foo", "c", "b", "a"]))
        tm.assert_series_equal(df["a"], df["foo"], check_names=False)

        df.insert(2, "bar", df["c"])
        self.assert_index_equal(df.columns, Index(["foo", "c", "bar", "b", "a"]))
        tm.assert_almost_equal(df["c"], df["bar"], check_names=False)

        # diff dtype

        # new item
        df["x"] = df["a"].astype("float32")
        result = Series(dict(float64=5, float32=1))
        self.assertTrue((df.get_dtype_counts() == result).all())

        # replacing current (in different block)
        df["a"] = df["a"].astype("float32")
        result = Series(dict(float64=4, float32=2))
        self.assertTrue((df.get_dtype_counts() == result).all())

        df["y"] = df["a"].astype("int32")
        result = Series(dict(float64=4, float32=2, int32=1))
        self.assertTrue((df.get_dtype_counts() == result).all())

        with assertRaisesRegexp(ValueError, "already exists"):
            df.insert(1, "a", df["b"])
        self.assertRaises(ValueError, df.insert, 1, "c", df["b"])

        df.columns.name = "some_name"
        # preserve columns name field
        df.insert(0, "baz", df["c"])
        self.assertEqual(df.columns.name, "some_name")

        # GH 13522
        df = DataFrame(index=["A", "B", "C"])
        df["X"] = df.index
        df["X"] = ["x", "y", "z"]
        exp = DataFrame(data={"X": ["x", "y", "z"]}, index=["A", "B", "C"])
        assert_frame_equal(df, exp)
    def test_column_dups_operations(self):
        def check(result, expected=None):
            if expected is not None:
                assert_frame_equal(result, expected)
            result.dtypes
            str(result)

        # assignment
        # GH 3687
        arr = np.random.randn(3, 2)
        idx = lrange(2)
        df = DataFrame(arr, columns=["A", "A"])
        df.columns = idx
        expected = DataFrame(arr, columns=idx)
        check(df, expected)

        idx = date_range("20130101", periods=4, freq="Q-NOV")
        df = DataFrame([[1, 1, 1, 5], [1, 1, 2, 5], [2, 1, 3, 5]], columns=["a", "a", "a", "a"])
        df.columns = idx
        expected = DataFrame([[1, 1, 1, 5], [1, 1, 2, 5], [2, 1, 3, 5]], columns=idx)
        check(df, expected)

        # insert
        df = DataFrame([[1, 1, 1, 5], [1, 1, 2, 5], [2, 1, 3, 5]], columns=["foo", "bar", "foo", "hello"])
        df["string"] = "bah"
        expected = DataFrame(
            [[1, 1, 1, 5, "bah"], [1, 1, 2, 5, "bah"], [2, 1, 3, 5, "bah"]],
            columns=["foo", "bar", "foo", "hello", "string"],
        )
        check(df, expected)
        with assertRaisesRegexp(ValueError, "Length of value"):
            df.insert(0, "AnotherColumn", range(len(df.index) - 1))

        # insert same dtype
        df["foo2"] = 3
        expected = DataFrame(
            [[1, 1, 1, 5, "bah", 3], [1, 1, 2, 5, "bah", 3], [2, 1, 3, 5, "bah", 3]],
            columns=["foo", "bar", "foo", "hello", "string", "foo2"],
        )
        check(df, expected)

        # set (non-dup)
        df["foo2"] = 4
        expected = DataFrame(
            [[1, 1, 1, 5, "bah", 4], [1, 1, 2, 5, "bah", 4], [2, 1, 3, 5, "bah", 4]],
            columns=["foo", "bar", "foo", "hello", "string", "foo2"],
        )
        check(df, expected)
        df["foo2"] = 3

        # delete (non dup)
        del df["bar"]
        expected = DataFrame(
            [[1, 1, 5, "bah", 3], [1, 2, 5, "bah", 3], [2, 3, 5, "bah", 3]],
            columns=["foo", "foo", "hello", "string", "foo2"],
        )
        check(df, expected)

        # try to delete again (its not consolidated)
        del df["hello"]
        expected = DataFrame(
            [[1, 1, "bah", 3], [1, 2, "bah", 3], [2, 3, "bah", 3]], columns=["foo", "foo", "string", "foo2"]
        )
        check(df, expected)

        # consolidate
        df = df.consolidate()
        expected = DataFrame(
            [[1, 1, "bah", 3], [1, 2, "bah", 3], [2, 3, "bah", 3]], columns=["foo", "foo", "string", "foo2"]
        )
        check(df, expected)

        # insert
        df.insert(2, "new_col", 5.0)
        expected = DataFrame(
            [[1, 1, 5.0, "bah", 3], [1, 2, 5.0, "bah", 3], [2, 3, 5.0, "bah", 3]],
            columns=["foo", "foo", "new_col", "string", "foo2"],
        )
        check(df, expected)

        # insert a dup
        assertRaisesRegexp(ValueError, "cannot insert", df.insert, 2, "new_col", 4.0)
        df.insert(2, "new_col", 4.0, allow_duplicates=True)
        expected = DataFrame(
            [[1, 1, 4.0, 5.0, "bah", 3], [1, 2, 4.0, 5.0, "bah", 3], [2, 3, 4.0, 5.0, "bah", 3]],
            columns=["foo", "foo", "new_col", "new_col", "string", "foo2"],
        )
        check(df, expected)

        # delete (dup)
        del df["foo"]
        expected = DataFrame(
            [[4.0, 5.0, "bah", 3], [4.0, 5.0, "bah", 3], [4.0, 5.0, "bah", 3]],
            columns=["new_col", "new_col", "string", "foo2"],
        )
        assert_frame_equal(df, expected)

        # dup across dtypes
        df = DataFrame([[1, 1, 1.0, 5], [1, 1, 2.0, 5], [2, 1, 3.0, 5]], columns=["foo", "bar", "foo", "hello"])
        check(df)

        df["foo2"] = 7.0
        expected = DataFrame(
            [[1, 1, 1.0, 5, 7.0], [1, 1, 2.0, 5, 7.0], [2, 1, 3.0, 5, 7.0]],
            columns=["foo", "bar", "foo", "hello", "foo2"],
        )
        check(df, expected)

        result = df["foo"]
        expected = DataFrame([[1, 1.0], [1, 2.0], [2, 3.0]], columns=["foo", "foo"])
        check(result, expected)

        # multiple replacements
        df["foo"] = "string"
        expected = DataFrame(
            [["string", 1, "string", 5, 7.0], ["string", 1, "string", 5, 7.0], ["string", 1, "string", 5, 7.0]],
            columns=["foo", "bar", "foo", "hello", "foo2"],
        )
        check(df, expected)

        del df["foo"]
        expected = DataFrame([[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "hello", "foo2"])
        check(df, expected)

        # values
        df = DataFrame([[1, 2.5], [3, 4.5]], index=[1, 2], columns=["x", "x"])
        result = df.values
        expected = np.array([[1, 2.5], [3, 4.5]])
        self.assertTrue((result == expected).all().all())

        # rename, GH 4403
        df4 = DataFrame(
            {"TClose": [22.02], "RT": [0.0454], "TExg": [0.0422]},
            index=MultiIndex.from_tuples([(600809, 20130331)], names=["STK_ID", "RPT_Date"]),
        )

        df5 = DataFrame(
            {
                "STK_ID": [600809] * 3,
                "RPT_Date": [20120930, 20121231, 20130331],
                "STK_Name": [u("饡驦"), u("饡驦"), u("饡驦")],
                "TClose": [38.05, 41.66, 30.01],
            },
            index=MultiIndex.from_tuples(
                [(600809, 20120930), (600809, 20121231), (600809, 20130331)], names=["STK_ID", "RPT_Date"]
            ),
        )

        k = pd.merge(df4, df5, how="inner", left_index=True, right_index=True)
        result = k.rename(columns={"TClose_x": "TClose", "TClose_y": "QT_Close"})
        str(result)
        result.dtypes

        expected = DataFrame(
            [[0.0454, 22.02, 0.0422, 20130331, 600809, u("饡驦"), 30.01]],
            columns=["RT", "TClose", "TExg", "RPT_Date", "STK_ID", "STK_Name", "QT_Close"],
        ).set_index(["STK_ID", "RPT_Date"], drop=False)
        assert_frame_equal(result, expected)

        # reindex is invalid!
        df = DataFrame([[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "a", "a"])
        self.assertRaises(ValueError, df.reindex, columns=["bar"])
        self.assertRaises(ValueError, df.reindex, columns=["bar", "foo"])

        # drop
        df = DataFrame([[1, 5, 7.0], [1, 5, 7.0], [1, 5, 7.0]], columns=["bar", "a", "a"])
        result = df.drop(["a"], axis=1)
        expected = DataFrame([[1], [1], [1]], columns=["bar"])
        check(result, expected)
        result = df.drop("a", axis=1)
        check(result, expected)

        # describe
        df = DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 3]], columns=["bar", "a", "a"], dtype="float64")
        result = df.describe()
        s = df.iloc[:, 0].describe()
        expected = pd.concat([s, s, s], keys=df.columns, axis=1)
        check(result, expected)

        # check column dups with index equal and not equal to df's index
        df = DataFrame(np.random.randn(5, 3), index=["a", "b", "c", "d", "e"], columns=["A", "B", "A"])
        for index in [df.index, pd.Index(list("edcba"))]:
            this_df = df.copy()
            expected_ser = pd.Series(index.values, index=this_df.index)
            expected_df = DataFrame.from_items([("A", expected_ser), ("B", this_df["B"]), ("A", expected_ser)])
            this_df["A"] = index
            check(this_df, expected_df)

        # operations
        for op in ["__add__", "__mul__", "__sub__", "__truediv__"]:
            df = DataFrame(dict(A=np.arange(10), B=np.random.rand(10)))
            expected = getattr(df, op)(df)
            expected.columns = ["A", "A"]
            df.columns = ["A", "A"]
            result = getattr(df, op)(df)
            check(result, expected)

        # multiple assignments that change dtypes
        # the location indexer is a slice
        # GH 6120
        df = DataFrame(np.random.randn(5, 2), columns=["that", "that"])
        expected = DataFrame(1.0, index=range(5), columns=["that", "that"])

        df["that"] = 1.0
        check(df, expected)

        df = DataFrame(np.random.rand(5, 2), columns=["that", "that"])
        expected = DataFrame(1, index=range(5), columns=["that", "that"])

        df["that"] = 1
        check(df, expected)
model_svc.probability = True
probas = model_svc.fit(ROCtrainTRN, ROCtrainTRG).predict_proba(ROCtestTRN)
fpr, tpr, thresholds = roc_curve(ROCtestTRG, probas[:, 1])
roc_auc  = auc(fpr, tpr)
pl.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('SVC', roc_auc))
#RandomForestClassifier
probas = model_rfc.fit(ROCtrainTRN, ROCtrainTRG).predict_proba(ROCtestTRN)
fpr, tpr, thresholds = roc_curve(ROCtestTRG, probas[:, 1])
roc_auc  = auc(fpr, tpr)
pl.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('RandonForest',roc_auc))
#KNeighborsClassifier
probas = model_knc.fit(ROCtrainTRN, ROCtrainTRG).predict_proba(ROCtestTRN)
fpr, tpr, thresholds = roc_curve(ROCtestTRG, probas[:, 1])
roc_auc  = auc(fpr, tpr)
pl.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('KNeighborsClassifier',roc_auc))
#LogisticRegression
probas = model_lr.fit(ROCtrainTRN, ROCtrainTRG).predict_proba(ROCtestTRN)
fpr, tpr, thresholds = roc_curve(ROCtestTRG, probas[:, 1])
roc_auc  = auc(fpr, tpr)
pl.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('LogisticRegression',roc_auc))
pl.plot([0, 1], [0, 1], 'k--')
pl.xlim([0.0, 1.0])
pl.ylim([0.0, 1.0])
pl.xlabel('False Positive Rate')
pl.ylabel('True Positive Rate')
pl.legend(loc=0, fontsize='small')
pl.show()

model_rfc.fit(train, target)
result.insert(1,'Survived', model_rfc.predict(test))
result.to_csv('Kaggle_Titanic/Result/test.csv', index=False)
Example #14
0
    def add_var2(self, varname, target=None, source="free"):
        """
        Add a variable in the dataframe

        Parameters
        ----------

        varname : str
                  name of the variable
        target : float
                 target for the margin of the variable
        source : str, default 'free'
                 database source
        """
        w_init = self.weights_init * self.champm
        w = self.weights * self.champm
        inputs = self.simulation.survey
        output_table = self.simulation.output_table

        varcol = self.simulation.get_col(varname)
        entity = self.entity
        enum = inputs.column_by_name.get("qui" + self.entity).enum
        people = [x[1] for x in enum]

        if varname in inputs.column_by_name:
            value = inputs.get_value(varname, index=idx)
        elif output_table is not None and varname in output_table.column_by_name:
            value = output_table.get_value(varname, index=idx, opt=people, sum_=True)

        label = varcol.label
        # TODO: rewrite this using pivot table
        items = [("marge", w[self.champm]), ("marge initiale", w_init[self.champm])]
        if varcol.__class__ in MODCOLS:
            items.append(("mod", value[self.champm]))
            df = DataFrame.from_items(items)
            res = df.groupby("mod", sort=True).sum()
        else:
            res = DataFrame(
                index=["total"], data={"marge": (value * w).sum(), "marge initiale": (value * w_init).sum()}
            )
        res.insert(0, u"modalités", u"")
        res.insert(2, "cible", 0)
        res.insert(2, u"cible ajustée", 0)
        res.insert(4, "source", source)
        mods = res.index

        if target is not None:
            if len(mods) != len(target.keys()):
                drop_indices = [(varname, mod) for mod in target.keys()]
                if source == "input":
                    self.input_margins_df.drop(drop_indices, inplace=True)
                    self.input_margins_df.index.names = ["var", "mod"]
                if source == "output":
                    self.output_margins_df.drop(drop_indices, inplace=True)
                    self.output_margins_df.index.names = ["var", "mod"]
                return

        if isinstance(varcol, EnumCol):
            if varcol.enum:
                enum = varcol.enum
                res[u"modalités"] = [enum._vars[mod] for mod in mods]
                res["mod"] = mods
            else:
                res[u"modalités"] = [mod for mod in mods]
                res["mod"] = mods
        elif isinstance(varcol, BoolCol) or isinstance(varcol, BoolPresta):
            res[u"modalités"] = bool(mods)
            res["mod"] = mods
        elif isinstance(varcol, IntPresta):
            res[u"modalités"] = mods
            res["mod"] = mods
        elif isinstance(varcol, AgesCol):
            res[u"modalités"] = mods
            res["mod"] = mods
        else:
            res[u"modalités"] = "total"
            res["mod"] = 0

        if label is not None:
            res["variable"] = label
        else:
            res["variable"] = varname
        res["var"] = varname

        if target is not None:
            for mod, margin in target.iteritems():
                if mod == varname:  # dirty to deal with non catgorical data
                    res["cible"][0] = margin
                else:
                    res["cible"][mod] = margin

        if self.frame is None:
            self.frame = res
        else:
            self.frame = concat([self.frame, res])

        self.frame = self.frame.reset_index(drop=True)