{ "cells": [ { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from pandasql import sqldf \n", "from sqlalchemy import create_engine\n", "import statsmodels.api as sm \n", "import numpy as np\n", "\n", "mysql_user = 'root'\n", "mysql_password = 'qx123456'\n", "mysql_host = 'algo-dev-internal.li-ai.com.cn'\n", "mysql_port = 3306\n", "mysql_db = 'algo'\n", "\n", "db_engine = create_engine(\"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8\".format(mysql_user, mysql_password, mysql_host, mysql_port, mysql_db),\n", " pool_recycle=7200,pool_size=2)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "sql=\"select day,slot,c_b_count from algo_dwd_station_change_flow where organ_code='qiaozhuang'\"\n", "\n", "change_data=pd.read_sql(sql, db_engine)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_3113831/1568745592.py:1: 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", " change_data['c_b_count'][change_data['c_b_count']>4]=4\n" ] } ], "source": [ "change_data['c_b_count'][change_data['c_b_count']>4]=4" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5762, 3)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "change_data.shape" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | day | \n", "slot | \n", "c_b_count | \n", "
---|---|---|---|
0 | \n", "2022-10-19 | \n", "13:30-13:59 | \n", "1 | \n", "
1 | \n", "2022-10-19 | \n", "14:00-14:29 | \n", "1 | \n", "
2 | \n", "2022-10-19 | \n", "14:30-14:59 | \n", "1 | \n", "
3 | \n", "2022-10-19 | \n", "15:00-15:29 | \n", "0 | \n", "
4 | \n", "2022-10-19 | \n", "15:30-15:59 | \n", "0 | \n", "