1

So I have two lists called A and C that each have the same amount of data points stored in them. I have created a new list called E that contains values in C that are greater than 400.

I need to make a plot of E vs. A My question is how do I get the corresponding values that I gained from creating E from the list A so that I can make a plot?

Is there a way to grab the data from A that corresponds with E which might make a new list I could plot? Thanks.

The data I am using is quite a large list, but here is an example:

    xpos,ypos,measurement,error
    96.54, 92.10, 236.69, 23.67
    26.26, 17.36, 457.55, 45.76
    96.15, 52.22, 369.31, 36.93
    53.23, 56.85, 630.77, 63.08
    82.48, 97.64, 198.24, 19.82

I have removed the headers and created four lists for each data column: A for the xpos, B for the ypos, C for measurement, and D for error.

C, or measurement is the data set that I edited to be E which has values over 400. I want to get the values from A (xpos) that match up across the row from the values over 400 in C (or measurement).

I am trying to plot in iPython notebook the list I got from E vs. the corresponding values in A.

4

3 回答 3

3

我会zip在计算 E 之前将 A 和 C 放在一起:

E_pairs = [pair for pair in zip(A, C) if pair[1] > 400]

这将为您提供 A 和 C 值的元组列表,其中 C 超过 400。

于 2014-07-23T22:08:49.283 回答
0
A=[100,300,400,200,500]

B=['a','b','c','d','e']

E=[[a,b] for a,b in zip(A,B)]

my_list=filter(lambda x:x[0]>400,E)
于 2014-07-23T22:11:28.080 回答
0

如果列表大小相同,您可以使用 enumerate 并列出每个列表:

final_a = []
final_c = []
for ind, x in enumerate(C):
    if x > 400:
        final_c.append(x)
        final_a.append(A[ind])
于 2014-07-23T22:35:20.970 回答