mixedmodels.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:histwords 作者: williamleif 项目源码 文件源码
def make_data_frame(words, years, feature_dict):
    """
    Makes a pandas dataframe for word, years, and dictionary of feature funcs.
    Each feature func should take (word, year) and return feature value.
    Constructed dataframe has flat csv style structure and missing values are removed.
    """

    temp = collections.defaultdict(list)
    feature_dict["word"] = lambda word, year : word
    feature_dict["year"] = lambda word, year : year
    for word in words:
        for year in years:
            for feature, feature_func in feature_dict.iteritems():
                temp[feature].append(feature_func(word, year))
    df = pd.DataFrame(temp)
    df = df.replace([np.inf, -np.inf], np.nan)
    df = df.dropna()
    return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号