如何只获取 Pandas 数据框的一列(没有索引)并将其放入双端队列?

How can I get only one column of Pandas dataframe (without index) and put it into deque?

我有一个不同公司的 .csv 格式:

Date (Key) Company 1 Company 2 ... Company n
01.01.2020 2 11 ... 3
02.01.2020 3 9 ... 45
... ... ... ... ...
01.11.2021 1 12 ... 34

我将公司本身保存在股票代码文件中。我现在的目标是以以下形式的双端队列加载这些数据:

[[Company 1] [2 3 ... 1] [Company 2] [11 0 ... 12] ... [Company n] [3 45 ... 34]]

使用代码:

import pandas as pd
import pickle

from collections import deque

with open("Webscrapper/Sp500tickers.pickle", 'rb') as f:
    tickers = pickle.load(f)

df = pd.read_csv(f"Webscrapper/Sp500tickers_DailyChanges.csv", index_col="Date")

data = [[ticker, df[ticker][0:-1]] for ticker in tickers]
c = deque(data)
print(c)

我也得到了日期,表示形式数组

[[Company 1] [Date Company 1 01.01.2020 2 02.01.2020 2 3 ... 01.11.2021 1] [Company 2] [Date Company 2 01.01.2020 11 02.01.2020 0 ... 01.11.2021 12] ... [Company n] [Date Company n 01.01.2020 3 02.01.2020 45 ... 01.11.2021 34]]

如何将数组转换为所需的形式?

使用Series.tolist将列的值转换为列表

data = [[ticker, df[ticker].tolist()] for ticker in tickers]
c = deque(data)