K
K
kOFFtan2021-12-09 19:44:24
Python
kOFFtan, 2021-12-09 19:44:24

I can't solve the problem in Yandex.Practice. Fundamentals of Python and data analysis, topic 7, lesson 9?

This code works, but the program does not accept a response, tell me what I missed?

When checking, it gives:
Incorrect value of the variable error_yield
Item 0:
2549811575.1209617
^

1. Calculate the prediction errors for the first strategy - the area of ​​crops is real, and the yield is last year.
Create a list of error_acres and add to it the difference between the actual and the predicted crop for every year except 1980. In order not to get confused with indexes, do not create a separate list for predictions, as in the previous lesson. Instead, immediately subtract the product of the actual crop area and last year's yield from the actual crop for a given year.
Then build a bar chart with the x-axis for years since 1981 and the y-axis for error_acres.

2. Do the same for the second strategy - the area of ​​crops is last year, and the yield is real. Save the results in the error_yield list. Then build a bar chart with the x-axis for years since 1981 and the y-axis for error_yield.

The first task was solved without problems.
I would be grateful if anyone can help me to solve the problem. Thank you!

import pandas
data = pandas.read_csv('crops_usa.csv')

acres = list(data['Acres'])
production = list(data['Production'])
years = list(data['Year'])

acres_usa = []
production_usa = []

for year in range(1980, 2020):
    acres_one_year = []
    production_one_year = []
    for index in range(len(data)):
        if years[index] == year:
            acres_one_year.append(acres[index])
            production_one_year.append(production[index])
    acres_usa.append(sum(acres_one_year))
    production_usa.append(sum(production_one_year))

yield_usa = []

for index in range(len(production_usa)):
    yield_usa.append(production_usa[index] / acres_usa[index])
years_numbers = list(range(1980, 2020))
    
error_yield = []
for index in range(1, len(production_usa)):
    error_yield.append(acres_usa[index - 1] * yield_usa[index])

import seaborn
seaborn.barplot(x = years_numbers[1:], y = error_yield)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Larin, 2021-12-10
@kOFFtan

import pandas
data = pandas.read_csv('crops_usa.csv')

acres = list(data['Acres'])
production = list(data['Production'])
years = list(data['Year'])

acres_usa = []
production_usa = []

for year in range(1980, 2020):
    acres_one_year = []
    production_one_year = []
    for index in range(len(data)):
        if years[index] == year:
            acres_one_year.append(acres[index])
            production_one_year.append(production[index])
    acres_usa.append(sum(acres_one_year))
    production_usa.append(sum(production_one_year))

yield_usa = []

for index in range(len(production_usa)):
    yield_usa.append(production_usa[index] / acres_usa[index])
years_numbers = list(range(1980, 2020))
    
error_yield = []

for index in range(1, len(yield_usa)):
    error_yield.append(production_usa[index] - acres_usa[index-1] * yield_usa[index])
    
import seaborn

seaborn.barplot(x=years_numbers[1:], y=error_yield)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question