从Dataframe加载对象

时间:2018-01-16 14:28:24

标签: python pandas oop dataframe

我有一个对象 Gene

class Gene:
    def __init__(self, id, nb_obj, nb_days):
        self.id=id
        self.nb_obj=nb_obj
        self.nb_days=nb_days

我有一个pandas数据框 df

   ID               nb_obj              nb_days
ECGYE                10259            62.965318
NLRTM                 8007            46.550562

如何将数据帧的每一行加载为 Gene 对象?

2 个答案:

答案 0 :(得分:1)

您可以使用调用Gene的构造函数的df.apply(lambda row: Gene(row['id'],row['nb_obj'],row['nb_days']), axis=1)

function custom_weird_name_before_after($content) {
if(is_page() || is_single() || $yourOwnConditions == true)  {
    $beforecontent = 'This line will go before the content - populate with whatever.';
    $aftercontent = 'This will come after the content - makes sense right?';
    $fullcontent = $beforecontent . $content . $aftercontent;
} else {
    $fullcontent = $content;
}

return $fullcontent;
}
add_filter('the_content', 'custom_weird_name_before_after');

答案 1 :(得分:0)

你可以试试这个:

[Gene(df.ID.loc[i], df.nb_obj.loc[i], df.nb_days.loc[i]) for i in range(df.shape[0])]