要组合dates和true_predictions来创建一个DataFrame,可以使用pandas库中的DataFrame函数。首先,导入pandas库:
import pandas as pd
然后,将dates和true_predictions作为字典的键值对传递给DataFrame函数,其中dates作为"dates"列,true_predictions作为"true_predictions"列。示例代码如下:
dates = ['2022-01-01', '2022-01-02', '2022-01-03']
true_predictions = [10, 15, 20]
df = pd.DataFrame({'dates': dates, 'true_predictions': true_predictions})
这样就创建了一个名为df的DataFrame,其中包含两列:"dates"和"true_predictions"。可以通过打印df来查看DataFrame的内容:
print(df)
输出结果如下:
dates true_predictions
0 2022-01-01 10
1 2022-01-02 15
2 2022-01-03 20
这样就成功地将dates和true_predictions组合成了一个DataFrame。
领取专属 10元无门槛券
手把手带您无忧上云