From f21f83d7a7f5906ab61a84ad012fb8e4eae13988 Mon Sep 17 00:00:00 2001 From: heshunme Date: Fri, 6 Sep 2024 15:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E9=A2=98=E6=89=80=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 作物数据处理.ipynb | 165 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 作物数据处理.ipynb diff --git a/作物数据处理.ipynb b/作物数据处理.ipynb new file mode 100644 index 0000000..3d8c615 --- /dev/null +++ b/作物数据处理.ipynb @@ -0,0 +1,165 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "markdown", + "source": "# 对于每种作物的数据统计", + "id": "493d1cd2ba436df4" + }, + { + "cell_type": "code", + "id": "initial_id", + "metadata": { + "collapsed": true, + "ExecuteTime": { + "end_time": "2024-09-06T03:48:24.933466Z", + "start_time": "2024-09-06T03:48:24.929071Z" + } + }, + "source": [ + "import pandas as pd\n", + "\n", + "LandType = {\"A\": \"平旱地\", \"B\": \"梯田\", \"C\": \"山坡地\", \"D\": \"水浇地\", \"E\": \"普通大棚\", \"F\": \"智慧大棚\"}\n" + ], + "outputs": [], + "execution_count": 6 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-09-06T03:47:13.186447Z", + "start_time": "2024-09-06T03:47:12.737363Z" + } + }, + "cell_type": "code", + "source": [ + "df_planting = pd.read_excel('./data/2.xlsx', sheet_name=0)\n", + "df_crop_details = pd.read_excel('./data/2.xlsx', sheet_name=1)" + ], + "id": "9f4633f8e90ffe1a", + "outputs": [], + "execution_count": 2 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-09-06T03:47:59.155110Z", + "start_time": "2024-09-06T03:47:59.146478Z" + } + }, + "cell_type": "code", + "source": [ + "df_planting['landName'] = df_planting['landName'].ffill()\n", + "df_crop_details['cropLandType'] = df_crop_details['cropLandType'].str.rstrip()" + ], + "id": "ef9302cf0dc64751", + "outputs": [], + "execution_count": 4 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-09-06T03:47:59.527406Z", + "start_time": "2024-09-06T03:47:59.512252Z" + } + }, + "cell_type": "code", + "source": [ + "def get_crop_price(crop_num, crop_land_type, season):\n", + " if crop_land_type==\"智慧大棚\" and season==\"第一季\":\n", + " crop_land_type = \"普通大棚\"\n", + " s = df_crop_details[(df_crop_details['cropNum'] == crop_num) & (df_crop_details['cropLandType'] == crop_land_type) & (\n", + " df_crop_details['season'] == season)].price.values[0].split('-')\n", + " return (float(s[0]) + float(s[1])) / 2\n", + "\n", + "def get_crop_yield(crop_num, crop_land_type, season):\n", + " if crop_land_type==\"智慧大棚\" and season==\"第一季\":\n", + " crop_land_type = \"普通大棚\"\n", + " return df_crop_details[(df_crop_details['cropNum'] == crop_num) & (df_crop_details['cropLandType'] == crop_land_type) & (\n", + " df_crop_details['season'] == season)].unitYield.values[0]\n", + "\n", + "def get_crop_cost(crop_num, crop_land_type, season):\n", + " if crop_land_type==\"智慧大棚\" and season==\"第一季\":\n", + " crop_land_type = \"普通大棚\"\n", + " return df_crop_details[(df_crop_details['cropNum'] == crop_num) & (df_crop_details['cropLandType'] == crop_land_type) & (\n", + " df_crop_details['season'] == season)].cost.values[0]" + ], + "id": "6571c03dd0a145d", + "outputs": [], + "execution_count": 5 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-09-06T03:49:20.091314Z", + "start_time": "2024-09-06T03:49:19.991837Z" + } + }, + "cell_type": "code", + "source": [ + "total_yield = {crop:0 for crop in df_crop_details['cropNum'].unique()}\n", + "total_cost = {crop:0 for crop in df_crop_details['cropNum'].unique()}\n", + "total_income = {crop:0 for crop in df_crop_details['cropNum'].unique()}\n", + "total_profit = {crop:0 for crop in df_crop_details['cropNum'].unique()}\n", + "for line in df_planting.values:\n", + " # print(line[1], LandType[line[0][0]], line[5])\n", + " yld = line[4] * get_crop_yield(line[1], LandType[line[0][0]], line[5])\n", + " cost = line[4] * get_crop_cost(line[1], LandType[line[0][0]], line[5])\n", + " income = yld * get_crop_price(line[1], LandType[line[0][0]], line[5])\n", + " profit = income - cost\n", + " \n", + " total_yield[line[1]] += yld\n", + " total_cost[line[1]] += cost\n", + " total_income[line[1]] += income\n", + " total_profit[line[1]] += profit\n", + "print(total_yield) # 总产量\n", + "print(total_cost) # 总开销\n", + "print(total_income) # 总收入\n", + "print(total_profit) # 总利润" + ], + "id": "483a03b545d80063", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1: 57000.0, 2: 21850.0, 3: 22400.0, 4: 33040.0, 5: 9875.0, 6: 170840.0, 7: 132750.0, 8: 71400.0, 9: 30000.0, 10: 12500.0, 11: 1500.0, 12: 35100.0, 13: 36000.0, 14: 14000.0, 15: 10000.0, 16: 21000.0, 17: 36480.0, 18: 26880.0, 19: 6480.0, 20: 30000.0, 21: 36210.0, 22: 45360.0, 23: 900.0, 24: 2610.0, 25: 3600.0, 26: 4050.0, 27: 4500.0, 28: 35480.0, 29: 13050.0, 30: 2850.0, 31: 1200.0, 32: 3600.0, 33: 1800.0, 34: 1800.0, 35: 150000.0, 36: 100000.0, 37: 36000.0, 38: 9000.0, 39: 7200.0, 40: 18000.0, 41: 4200.0}\n", + "{1: 58800.0, 2: 18400.0, 3: 21000.0, 4: 33600.0, 5: 8750.0, 6: 99900.0, 7: 67500.0, 8: 66600.0, 9: 20000.0, 10: 9000.0, 11: 5250.0, 12: 13000.0, 13: 36000.0, 14: 14000.0, 15: 7000.0, 16: 28560.0, 17: 24320.0, 18: 13440.0, 19: 4320.0, 20: 30000.0, 21: 30232.0, 22: 14232.0, 23: 900.0, 24: 1860.0, 25: 2700.0, 26: 3150.0, 27: 1800.0, 28: 17860.0, 29: 3255.0, 30: 1260.0, 31: 720.0, 32: 1500.0, 33: 750.0, 34: 360.0, 35: 60000.0, 36: 12500.0, 37: 6000.0, 38: 5400.0, 39: 3600.0, 40: 18000.0, 41: 42000.0}\n", + "{1: 185250.0, 2: 163875.0, 3: 184800.0, 4: 231280.0, 5: 66656.25, 6: 597940.0, 7: 398250.0, 8: 481950.0, 9: 180000.0, 10: 93750.0, 11: 60000.0, 12: 52650.0, 13: 117000.0, 14: 77000.0, 15: 35000.0, 16: 147000.0, 17: 291840.0, 18: 181440.0, 19: 42120.0, 20: 112500.0, 21: 227325.0, 22: 251856.0, 23: 6210.0, 24: 14958.0, 25: 19800.0, 26: 26325.0, 27: 22500.0, 28: 205252.0, 29: 97020.0, 30: 16380.000000000002, 31: 8700.0, 32: 16200.0, 33: 8100.0, 34: 8640.0, 35: 375000.0, 36: 250000.0, 37: 117000.0, 38: 517500.0, 39: 136800.0, 40: 288000.0, 41: 420000.0}\n", + "{1: 126450.0, 2: 145475.0, 3: 163800.0, 4: 197680.0, 5: 57906.25, 6: 498040.0, 7: 330750.0, 8: 415350.0, 9: 160000.0, 10: 84750.0, 11: 54750.0, 12: 39650.0, 13: 81000.0, 14: 63000.0, 15: 28000.0, 16: 118440.0, 17: 267520.0, 18: 168000.0, 19: 37800.0, 20: 82500.0, 21: 197093.0, 22: 237624.0, 23: 5310.0, 24: 13098.0, 25: 17100.0, 26: 23175.0, 27: 20700.0, 28: 187392.0, 29: 93765.0, 30: 15120.000000000002, 31: 7980.0, 32: 14700.0, 33: 7350.0, 34: 8280.0, 35: 315000.0, 36: 237500.0, 37: 111000.0, 38: 512100.0, 39: 133200.0, 40: 270000.0, 41: 378000.0}\n" + ] + } + ], + "execution_count": 10 + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": "", + "id": "4a082256506e1072" + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}