{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 读取文件/data/common/北京市科委/result/5U/20230514/part-00000-78a4fe44-ad5f-4ef9-935f-a6bb5fe03317-c000.csv\n", " 读取文件/data/common/北京市科委/result/5U/20230517/part-00000-70ef25e5-42c3-4c55-95b8-a39d3879afd9-c000.csv\n", " 读取文件/data/common/北京市科委/result/5U/20230520/part-00000-351b68a8-c075-4a99-979c-6dc10acf5d3b-c000.csv\n" ] } ], "source": [ "import os\n", "import pandas as pd\n", "base_dir = '/data/common/北京市科委/result'\n", "factorys = os.listdir(base_dir)\n", "factorys.sort()\n", "factorys=['5U']\n", "df_all=pd.DataFrame()\n", "for factory in factorys:\n", " dates = os.listdir(os.path.join(base_dir, factory))\n", " dates.sort()\n", " for date in dates:\n", " files = os.listdir(os.path.join(base_dir, factory, date))\n", " for f in files:\n", " if f.endswith(\".csv\"):\n", " file_path = os.path.join(base_dir, factory, date, f)\n", " print(f\" 读取文件{file_path}\")\n", " df = pd.read_csv(file_path)\n", " if len(df_all)==0:\n", " df_all=df\n", " else:\n", " df_all=df_all=df.append(df)\n", " break\n", "df.columns=['cellid','equipmentid','operatorid','ChargingMetaInfoId','updateDatetime','cellStatus','doorStatus','errorcode','current','voltage',\n", " 'power','quantity','envTemperature','cirTemprature','residualCurrent','startChargeSwq','receivedByPlatformDatetime']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "xx=df['cellid'].drop_duplicates()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_806639/1630412067.py:4: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df['flag'][df['current']>0.1]='c'\n" ] } ], "source": [ "df=df.sort_values([\"cellid\",\"updateDatetime\"],ascending = [True, True])\n", "df['flag']='d'\n", "if len(df['current']>0.1):\n", " df['flag'][df['current']>0.1]='c'\n", "df['flag_block']=(df[\"flag\"].shift(1) != df[\"flag\"]).astype(int).cumsum()\n", "df_c=df[df['flag']=='c']\n", "df_c_time_b=df_c[[\"updateDatetime\",\"cellid\",\"flag_block\"]].groupby([\"cellid\",\"flag_block\"]).first()\n", "df_c_time_e=df_c[[\"updateDatetime\",\"cellid\",\"flag_block\"]].groupby([\"cellid\",\"flag_block\"]).last()\n", "frames=[df_c_time_b,df_c_time_e]\n", "df_merge_c_choice = pd.concat(frames, axis=1, join='inner')\n", "df_merge_c_choice=df_merge_c_choice.reset_index()\n", "df_merge_c_choice.columns=[\"cellid\",\"charge_block\",\"time_first\",\"time_last\"]\n", "df_merge_c_choice[\"order_delta\"]=pd.to_timedelta(pd.to_datetime(df_merge_c_choice[\"time_last\"])-pd.to_datetime(df_merge_c_choice[\"time_first\"])).dt.total_seconds()\n", "df_merge_c_choice[\"order_delta_h\"]=round(df_merge_c_choice[\"order_delta\"]/3600,2)\n", "df_merge_c_choice_result1=df_merge_c_choice[df_merge_c_choice[\"order_delta\"]>=300]\n", "df_merge_c21=df_c[(df_c[\"cellid\"].isin(df_merge_c_choice_result1[\"cellid\"]))&(df_c[\"flag_block\"].isin(df_merge_c_choice_result1[\"charge_block\"]))]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "17" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "zz=df_merge_c21['flag_block'].drop_duplicates()\n", "len(zz)" ] } ], "metadata": { "kernelspec": { "display_name": "py3916", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }