Python-CSV到矩阵

Python-CSV到矩阵,python,csv,matrix,Python,Csv,Matrix,你能帮我解决这个问题吗 我是编程新手,想了解如何创建矩阵,如下所示: matrix = {"hello":["one","two","three"], "world": ["five","six","seven"], "goodbye":["one","two","three"]} 我想导入一个csv,里面有所有的字符串(1,2,3,…),我尝试了split方法,但是我没有做到。。。 另一个问题是类别的名称(你好,世界,再见) 您有什么建议吗?您研究过c

你能帮我解决这个问题吗

我是编程新手,想了解如何创建矩阵,如下所示:

matrix = {"hello":["one","two","three"],
          "world": ["five","six","seven"],
          "goodbye":["one","two","three"]}
我想导入一个csv,里面有所有的字符串(1,2,3,…),我尝试了split方法,但是我没有做到。。。 另一个问题是类别的名称(你好,世界,再见)


您有什么建议吗?

您研究过csv模块吗?


如果你发布了一篇文章,你会增加变化以得到一个好的答案。例如,添加您的csv文件的示例内容。首先,您引用的数据结构不是矩阵,而是字典,您能否展示您的csv看起来如何以及如何读取它?
import csv

TEST_TEXT = """\
hello,one,two,three
world,four,five,six
goodbye,one,two,three"""

TEST_FILE = TEST_TEXT.split("\n")
#file objects iterate over newlines anyway
#so this is how it would be when opening a file

#this would be the minimum needed to use the csv reader object:
for row in csv.reader(TEST_FILE):
    print(row)

#or to get a list of all the rows you can use this:
as_list = list(csv.reader(TEST_FILE))

#splitting off the first element and using it as the key in a dictionary
dict_I_call_matrix = {row[0]:row[1:] for row in csv.reader(TEST_FILE)}
print(dict_I_call_matrix)



without_csv = [row.split(",")  for row in TEST_FILE] #...row in TEST_TEXT.split("\n")]

matrix = [row[1:] for row in without_csv]
labels = [row[0] for row in without_csv]