Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python字典用于循环用于打印的csv头_Python_Dictionary_Key - Fatal编程技术网

Python字典用于循环用于打印的csv头

Python字典用于循环用于打印的csv头,python,dictionary,key,Python,Dictionary,Key,Python新手在这里,我的目标是将csv加载到一个数据帧中,这样我就可以循环遍历每个标题来绘制单独的分布 我想使用字典将标题存储为键,将数据存储为值列表,如下所示: header1: [1,2,3,4,5] header2: [6,7,8,9,10] 然后我想迭代我的header_列表中的所有header(不确定这是否是最好的方法)来绘图 感谢您的帮助。你可能会说我不知道我在做什么。你最好在df列上循环 df = pd.read_csv(PATH + 'my_input.csv', sep=

Python新手在这里,我的目标是将csv加载到一个数据帧中,这样我就可以循环遍历每个标题来绘制单独的分布

我想使用字典将标题存储为键,将数据存储为值列表,如下所示:

header1: [1,2,3,4,5]
header2: [6,7,8,9,10]
然后我想迭代我的header_列表中的所有header(不确定这是否是最好的方法)来绘图


感谢您的帮助。你可能会说我不知道我在做什么。

你最好在df列上循环

df = pd.read_csv(PATH + 'my_input.csv', sep=',', header=True)

# df.columns has the header
for column in df.columns:
    plt.plot(df[column], label=column)
plt.show()

你的代码有效吗?如果是,问题在哪里?如果没有,它做什么?您希望它做什么?还可以添加一个示例csv文件,以便我们可以获得上下文
df = pd.read_csv(PATH + 'my_input.csv', sep=',', header=True)

# df.columns has the header
for column in df.columns:
    plt.plot(df[column], label=column)
plt.show()