gpt4 book ai didi

python - 如何为 PyTorch 神经网络加载 CSV 数据?

转载 作者:行者123 更新时间:2023-12-03 23:49:32 24 4
gpt4 key购买 nike

这可能是一个简单的问题,如果太简单,我深表歉意。但我在 CSV 中有一些数据:

Date,Open,High,Low,Close,Adj Close,Volume
1993-01-29,43.968750,43.968750,43.750000,43.937500,26.453930,1003200
1993-02-01,43.968750,44.250000,43.968750,44.250000,26.642057,480500
1993-02-02,44.218750,44.375000,44.125000,44.343750,26.698507,201300
1993-02-03,44.406250,44.843750,44.375000,44.812500,26.980742,529400
1993-02-04,44.968750,45.093750,44.468750,45.000000,27.093624,531500
1993-02-05,44.968750,45.062500,44.718750,44.968750,27.074818,492100
1993-02-08,44.968750,45.125000,44.906250,44.968750,27.074818,596100
1993-02-09,44.812500,44.812500,44.562500,44.656250,26.886669,122100
....

我想创建一个“训练集”,它基本上是从文件中的任何地方随机采样的 10 行数据(我可以计算出标准化等)的随机向量。我想我必须使用 pandas做加载也许?

如果我想问的不清楚,请添加评论,我会相应地调整问题。谢谢你。

最佳答案

import pandas as pd

sample = pd.read_csv('myfile.csv').sample(n=10)

您应该只加载文件 1 次,然后边走边采样:
df = pd.read_csv('myfile.csv')
sample1 = df.sample(n=10)
sample2 = df.sample(n=10)

关于python - 如何为 PyTorch 神经网络加载 CSV 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com