如何从列中提取数据

b09cbbtk  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(498)

panda从一个url接收数据并生成一个数据表,如何从这个dataframe中将一个特定的列提取到一个列表中。具体来说,下面是我的代码,允许panda从url检索信息

url="https://pkgstore.datahub.io/core/nasdaq-listings/nasdaq-listed_csv/data/7665719fb51081ba0bd834fde71ce822/nasdaq-listed_csv.csv"
req = requests.get(url).content
companies = pd.read_csv(io.StringIO(req.decode('utf-8')))

当我这么做的时候 print(companies) 我得到以下结果:result
我的期望输出是能够将数据从symbol列提取到一个列表中,这样列表将包含 ['Symbol', 'AAIT', 'AAL', ...'ZUMZ']

q0qdq0h2

q0qdq0h21#

这应该适用于您的用例:


# You can create the Symbols list with this:

symbols_list = companies['Symbol'].to_list()

# This is not really needed. But as you want to have "Symbol" word at the start, you can do the following

your_desired_list = ['Symbol']
your_desired_list += symbols_list

相关问题