Question

-179.750 71.250 -20.1 -16.1 -19.0 -15.2 -5.1 -0.7 2.9 4.8 0.9 -3.5 -5.3 -19.0 -179.750 68.750...

-179.750 71.250 -20.1 -16.1 -19.0 -15.2 -5.1 -0.7 2.9 4.8 0.9 -3.5 -5.3 -19.0
-179.750 68.750 -23.3 -18.8 -22.7 -16.1 -6.0 -0.2 4.0 5.0 0.9 -5.3 -8.8 -22.2
-179.750 68.250 -23.8 -20.1 -24.1 -16.9 -7.0 -0.2 4.1 4.9 0.2 -6.6 -10.0 -22.7
-179.750 67.750 -22.6 -19.6 -23.6 -15.9 -5.8 2.3 7.1 7.3 1.5 -6.6 -9.9 -21.7
-179.750 67.250 -24.4 -22.6 -26.4 -18.2 -7.7 1.8 7.3 6.7 -0.5 -10.1 -13.3 -24.3

(txt file values provided above)

---------------------

Hello!! Could someone please help me that, skip using the first column

and each value per row in the second column if greater than 68.500, elif less than 68.250,

please takes the list of lists and an integer column index.

Returns a new list that contains the average values of the target column from all of the rows.

---------------------

if list[1] >= 68.500, the lists which would be used are this:

-179.750 71.250 -20.1 -16.1 -19.0 -15.2 -5.1 -0.7 2.9 4.8 0.9 -3.5 -5.3 -19.0
-179.750 68.750 -23.3 -18.8 -22.7 -16.1 -6.0 -0.2 4.0 5.0 0.9 -5.3 -8.8 -22.2

---------------------

if list[1] <=68.250, the lists which would be used are this:

-179.750 68.250 -23.8 -20.1 -24.1 -16.9 -7.0 -0.2 4.1 4.9 0.2 -6.6 -10.0 -22.7
-179.750 67.750 -22.6 -19.6 -23.6 -15.9 -5.8 2.3 7.1 7.3 1.5 -6.6 -9.9 -21.7
-179.750 67.250 -24.4 -22.6 -26.4 -18.2 -7.7 1.8 7.3 6.7 -0.5 -10.1 -13.3 -24.3

---------------------

both output: [average of column 2, avg of column 3, .... , avg of final column]

---------------------

Please do this in python,

Thank you!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

l=[]
fh = open('values.txt')
while True:
line = fh.readline()
if line!='':
l.append(line.split())
if not line:
break
fh.close()
sum1=[]
sum2=[]
for i in l:
if float(i[1])>=68.500:
sum1.append(i[1::])
elif float(i[1])<=68.250:
sum2.append(i[1::])
sum1 = [[float(j) for j in i] for i in sum1]
sum2 = [[float(j) for j in i] for i in sum2]

avg1=[sum(x) for x in zip(*sum1)]
avg2=[sum(x) for x in zip(*sum2)]

avg1=list(map(lambda x : x/len(sum1),avg1))
avg2=list(map(lambda x : x/len(sum2),avg2))
  
print(avg1)
print(avg2)

It may not be very elegant, strictly sticking to pure python. It's a lot simpler with numpy but since you specified 'list of lists', I stuck to the basics.

Hope it helps let me know if you require further assistance.

Add a comment
Know the answer?
Add Answer to:
-179.750 71.250 -20.1 -16.1 -19.0 -15.2 -5.1 -0.7 2.9 4.8 0.9 -3.5 -5.3 -19.0 -179.750 68.750...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can u clearly show me how to find a sample size (N) , A2, and can...

    can u clearly show me how to find a sample size (N) , A2, and can you also tell me why we are using an X Chart? Problem 1 A restaurant wants to control kitchen preparation time of dinner meals using an X chart. The process standard deviation is unknown. Each evening a manager takes a random sample of 14 dinner orders and measures and records their kitchen preparation time. Create an X Chart using data in the table below...

  • a) Insert here a copy of the plot for the heating curve you created in laboratory....

    a) Insert here a copy of the plot for the heating curve you created in laboratory. Remember that an acceptable plot has labels and units on the axes, a legend, and a title. PLOT GRAPH Run 1 Time   Temperature   T   T   min   °C   0.0   22.0   0.2   22.0   0.5   22.1   0.8   21.9   1.0   22.2   1.2   22.1   1.5   22.1   1.8   22.3   2.0   22.0   2.2   21.9   2.5   22.0   2.8   22.2   3.0   22.7   3.2   23.6   3.5   24.7   3.8   26.5   4.0   28.0   4.2   29.6   4.5  ...

  • We are interested in the relationship between the compensation of Chief Executive Officers (CEO) ...

    We are interested in the relationship between the compensation of Chief Executive Officers (CEO) of firms and the return on equity of their respective firm, using the dataset below. The variable salary shows the annual salary of a CEO in thousands of dollars, so that y = 150 indicates a salary of $150,000. Similarly, the variable ROE represents the average return on equity (ROE)for the CEO’s firm for the previous three years. A ROE of 20 indicates an average return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT