{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2026-01-30T09:27:59.557746200Z", "start_time": "2026-01-30T09:27:59.437881100Z" } }, "source": [ "import pandas as pd\n", "\n", "# 假设你的 DataFrame 名为 df,包含以下列:\n", "# 'material_code': 材料编码\n", "# 'in_qty': 入库数量\n", "# 'in_cost': 入库成本(总金额,不是单价)\n", "df = pd.read_excel(fr\"C:\\Users\\hp_z66\\OneDrive\\Desktop\\材料成本明细表核对.xlsx\",sheet_name='Sheet1')\n", "# 1. 按材料编码分组,计算总入库数量和总入库成本\n", "summary = df.groupby('材料编码').agg(\n", " total_in_qty=('数量', 'sum'),\n", " total_in_cost=(' 除税成本', 'sum')\n", ").reset_index()\n", "\n", "print(summary)\n", "summary.to_csv(fr\"C:\\Users\\hp_z66\\OneDrive\\Desktop\\材料成本明细表核对sheet1.csv\")" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 材料编码 total_in_qty total_in_cost\n", "0 CL0003899 8 184.07\n", "1 CL0004029 300 92.92\n", "2 CL0004193 100 176.99\n", "3 CL0005552 -1 -4250.04\n", "4 CL0005554 2 2268.78\n", ".. ... ... ...\n", "461 CL0007466 1 800.00\n", "462 CL0007467 1 800.00\n", "463 CL0007468 1 500.00\n", "464 CL0007469 1 500.00\n", "465 CL0007470 1 500.00\n", "\n", "[466 rows x 3 columns]\n" ] } ], "execution_count": 3 }, { "metadata": { "ExecuteTime": { "end_time": "2026-01-30T09:28:27.291489100Z", "start_time": "2026-01-30T09:28:27.188359600Z" } }, "cell_type": "code", "source": [ "import pandas as pd\n", "\n", "# 假设你的 DataFrame 名为 df,包含以下列:\n", "# 'material_code': 材料编码\n", "# 'in_qty': 入库数量\n", "# 'in_cost': 入库成本(总金额,不是单价)\n", "df = pd.read_excel(fr\"C:\\Users\\hp_z66\\OneDrive\\Desktop\\材料成本明细表核对.xlsx\",sheet_name='Sheet2')\n", "# 1. 按材料编码分组,计算总入库数量和总入库成本\n", "summary = df.groupby('材料编码').agg(\n", " total_in_qty=('采购入库数量', 'sum'),\n", " total_in_cost=('采购入库成本(除税)', 'sum')\n", ").reset_index()\n", "\n", "print(summary)\n", "summary.to_csv(fr\"C:\\Users\\hp_z66\\OneDrive\\Desktop\\材料成本明细表核对sheet2.csv\")" ], "id": "fcb775d7ed25bd85", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 材料编码 total_in_qty total_in_cost\n", "0 CL0003899 8 184.070800\n", "1 CL0004029 300 92.920500\n", "2 CL0004193 100 176.991200\n", "3 CL0005552 -1 -4250.044248\n", "4 CL0005554 2 2268.778762\n", ".. ... ... ...\n", "459 CL0007466 1 800.000000\n", "460 CL0007467 1 800.000000\n", "461 CL0007468 1 500.000000\n", "462 CL0007469 1 500.000000\n", "463 CL0007470 1 500.000000\n", "\n", "[464 rows x 3 columns]\n" ] } ], "execution_count": 5 } ], "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 }