build_df.py 文件源码

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

项目:fake_news 作者: bmassman 项目源码 文件源码
def build_df(table: str = 'articles',
             start_date: Optional[datetime] = None,
             end_date: Optional[datetime] = None) -> pd.DataFrame:
    """Build dataframe with derived fields."""
    with closing(sqlite3.connect(DB_FILE_NAME)) as conn:
        articles = pd.read_sql_query(f'select * from {table}', conn)
    articles['date'] = pd.to_datetime(articles['publish_date'])
    if start_date:
        articles = articles.loc[articles['date'] >= start_date]
    if end_date:
        articles = articles.loc[articles['date'] <= end_date]

    articles = articles.replace([None], [''], regex=True)
    articles['base_url'] = articles.apply(get_url_base, axis=1)
    articles['word_count'] = articles.apply(count_words, axis=1)
    return articles
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号