Advertisement
Yamilov

Untitled

Nov 6th, 2021
1,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas
  2. data = pandas.read_csv('crops_usa.csv')
  3.  
  4. acres = list(data['Acres'])
  5. production = list(data['Production'])
  6. years = list(data['Year'])
  7.  
  8. acres_usa = []
  9. production_usa = []
  10.  
  11. for year in range(1980, 2020):
  12.     acres_one_year = []
  13.     production_one_year = []
  14.     for index in range(len(data)):
  15.         if years[index] == year:
  16.             acres_one_year.append(acres[index])
  17.             production_one_year.append(production[index])
  18.     acres_usa.append(sum(acres_one_year))
  19.     production_usa.append(sum(production_one_year))
  20.  
  21. yield_usa = []
  22.  
  23. for index in range(len(production_usa)):
  24.     yield_usa.append(production_usa[index] / acres_usa[index])
  25.  
  26. predict_acres=[]     # создаем пустой список
  27. for index in range(1, len(acres_usa)):     # цикл, перебирает все значения столбца, кроме первого, то есть 1980 года
  28.     predict_acres.append(acres_one_year[index]*yield_usa[index-1])   #добавляем в пустой список результат умножения площади посевов за текущий год на урожайность за прошлый год
  29.  
  30.  
  31. print(predict_acres)
  32.  
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement