如何创建形状为 [244, 14] 的特征数据框,类似于使用 tqdm 的初始数据框?

How do I create a feature dataframe with shape of [244, 14], similar to that of the initial dataframe using tqdm?

下面是我试过的:

rows=[]
for _, row in tqdm(df.iterrows(),total=df.shape[0]):
    row_data=dict(
        week_of_year=row.date.week,
                month=row.date.month,
                    NGTC=row.NGTC,
                    NGRRO=row.NGRRO,
                    CSP=row.CSP,
                    NGMP=row.NGMP,
                    NGPI=row.NGPI,
                    NGUSV=row.NGUSV,
                    HOSP=row.HOSP,
                    HDD=row.HDD,
                    CDD=row.CDD,
                    NGSP=row.NGSP,
                    pre_NGSP=row.pre_NGSP,
            change_NGSP=row.change_NGSP)
    
rows.append(row_data)

我试过上面的代码后,发现我的features_df.shape[1,14],而不是[244,14]。请问我该如何解决这个问题?

你在 rows.append(row_data) 处写错了缩进,它不在循环中,所以你只得到了行中的最后一行。

rows=[]
    for _, row in tqdm(df.iterrows(),total=df.shape[0]):
        row_data=dict(
            week_of_year=row.date.week,
                   month=row.date.month,
                     NGTC=row.NGTC,
                     NGRRO=row.NGRRO,
                     CSP=row.CSP,
                     NGMP=row.NGMP,
                     NGPI=row.NGPI,
                     NGUSV=row.NGUSV,
                     HOSP=row.HOSP,
                     HDD=row.HDD,
                     CDD=row.CDD,
                     NGSP=row.NGSP,
                     pre_NGSP=row.pre_NGSP,
                change_NGSP=row.change_NGSP)
    
        rows.append(row_data).