简体   繁体   English

将多列数据放入一个数组中,python

[英]Putting multiple columns of data into one array, python

So I have a set of data which has a singular column for x data and multiple columns for y data, of the form.所以我有一组数据,其中 x 数据有一个单列,y 数据有多个列,形式为。

x_title     y_title_1    y_title_2   y_title_3 ....   y_title_n
data_x1     data_y2      data_y3     data_y4          data_yn
....        ....         ....        ....      ....   ....

I am trying to graph the data, a different plot for each y_data_i, on the same graph.我试图在同一张图上绘制数据,每个 y_data_i 的不同图。

I am using numpy arrays, matplotlib and scipy.我正在使用 numpy 数组、matplotlib 和 scipy。 And genfromtxt to read it in. I imagine the best way would be to put each column into an array, so there is an array for y_data_1,y_data_2 and so on.和 genfromtxt 读取它。我想最好的方法是将每一列放入一个数组中,因此有一个用于 y_data_1、y_data_2 等的数组。 However I have no idea how to do this?但是我不知道该怎么做? I know how to read them in singularly, to a set data, so:我知道如何将它们单独读取到一组数据中,因此:

y_data_1=data[0:number_of_rows,1] 

However I don't know how to code a way to do it for hundreds of columns.但是我不知道如何为数百列编写一种方法。

The basic plotting function would be:基本的绘图功能是:

import matplotlib.pyplot as plt
x = data[0]
for y in data[1:]:
    plt.plot(x, y)
plt.show()

where data[0] is your first column, and data[1:] is everything except the first column.其中 data[0] 是您的第一列,而 data[1:] 是除第一列之外的所有内容。

See here for more options.请参阅此处了解更多选项。

>>>import pandas as pd
>>>create a new series
>>>ser1 = pd.Series()
>>>col = [x for x in df.columns]
   df is values of csv data 
>>>for i in range(N):
   N is no of columns
   >>>ser1 = ser1.append(df[i])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM