【问题标题】:How to store lists in a variable as a data frame in Python?如何在 Python 中将列表作为数据框存储在变量中?
【发布时间】:2021-02-12 06:04:58
【问题描述】:

我正在尝试将这些列表存储在从循环创建的变量中作为数据框。

X_train = X[new_features]
X_test = X_test[new_features]
X_outliers = test_outlier[new_features]
l = new_features

当我打印l 时,它看起来像下面这样。它在循环内有 180 个列表。

['mfcc_1' 'mfcc_2' 'mfcc_4' 'mfcc_6' 'mfcc_3' 'mfcc_5' 'delta_0' 'mfcc_8'
 'mfcc_9' 'mfcc_7']
['mfcc_1' 'mfcc_2' 'mfcc_3' 'mfcc_4' 'delta_0' 'mfcc_5' 'mfcc_6' 'mfcc_7'
 'mfcc_8' 'mfcc_9']
['mfcc_1' 'mfcc_2' 'mfcc_4' 'mfcc_3' 'mfcc_6' 'mfcc_5' 'delta_0' 'mfcc_8'
 'mfcc_7' 'mfcc_10']
['mfcc_1' 'mfcc_2' 'mfcc_4' 'mfcc_6' 'mfcc_3' 'mfcc_5' 'mfcc_8' 'mfcc_7'
 'mfcc_10' 'delta_0']
['mfcc_1' 'mfcc_2' 'mfcc_3' 'mfcc_4' 'mfcc_6' 'delta_0' 'mfcc_5' 'mfcc_8'
 'mfcc_7' 'mfcc_10']
['mfcc_1' 'mfcc_2' 'mfcc_3' 'mfcc_4' 'mfcc_6' 'delta_0' 'mfcc_5' 'mfcc_8'
 'mfcc_7' 'mfcc_10'] ...

我想将这些列表存储到数据框中。怎么可能呢?

【问题讨论】:

标签: python list dataframe loops store


【解决方案1】:

使用df = pd.DataFrame({'col':l})

这个问题也非常不清楚。请添加您期望输出的示例,以便我们为您提供帮助。

参考for more information.

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2023-03-30
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多