← 返回题库
初级

解析issueDate提取年份和月份

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    loans_raw_csv = open_url("https://data.zuihe.com/dbd/riskctrl/state_02/loans_raw.csv").read()
    loans_clean_csv = open_url("https://data.zuihe.com/dbd/riskctrl/state_02/loans_clean.csv").read()
    import pandas as pd
    from io import StringIO
    df = pd.read_csv(StringIO(loans_raw_csv))
    df['issue_dt'] = pd.to_datetime(df['issueDate'],errors='coerce')
    df['issue_year'] = df['issue_dt'].dt.year
    df['issue_month'] = df['issue_dt'].dt.month
    print("issue_year分布(前5):")
    print(df['issue_year'].value_counts().head(5).to_string())
    print("issue_month分布(前5):")
    print(df['issue_month'].value_counts().sort_index().head(5).to_string())

示例

输入
solve()
期望输出
issue_year分布(前5):
issue_year
2015    2831
2016    2128
2014    1652
2017    1264
2013     972
issue_month分布(前5):
issue_month
1    837
2    771
3    947
4    768
5    836
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码