{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.522951Z",
     "end_time": "2025-02-09T20:52:57.531694Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.526116Z",
     "end_time": "2025-02-09T20:52:57.559094Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "       MSN  YYYYMM   Value  Column_Order  \\\n0  CLEIEUS  197301  72.076             1   \n1  CLEIEUS  197302  64.442             1   \n2  CLEIEUS  197303  64.084             1   \n3  CLEIEUS  197304  60.842             1   \n4  CLEIEUS  197305  61.798             1   \n\n                                Description  \\\n0  Coal Electric Power Sector CO2 Emissions   \n1  Coal Electric Power Sector CO2 Emissions   \n2  Coal Electric Power Sector CO2 Emissions   \n3  Coal Electric Power Sector CO2 Emissions   \n4  Coal Electric Power Sector CO2 Emissions   \n\n                                    Unit  \n0  Million Metric Tons of Carbon Dioxide  \n1  Million Metric Tons of Carbon Dioxide  \n2  Million Metric Tons of Carbon Dioxide  \n3  Million Metric Tons of Carbon Dioxide  \n4  Million Metric Tons of Carbon Dioxide  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>MSN</th>\n      <th>YYYYMM</th>\n      <th>Value</th>\n      <th>Column_Order</th>\n      <th>Description</th>\n      <th>Unit</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>CLEIEUS</td>\n      <td>197301</td>\n      <td>72.076</td>\n      <td>1</td>\n      <td>Coal Electric Power Sector CO2 Emissions</td>\n      <td>Million Metric Tons of Carbon Dioxide</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>CLEIEUS</td>\n      <td>197302</td>\n      <td>64.442</td>\n      <td>1</td>\n      <td>Coal Electric Power Sector CO2 Emissions</td>\n      <td>Million Metric Tons of Carbon Dioxide</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>CLEIEUS</td>\n      <td>197303</td>\n      <td>64.084</td>\n      <td>1</td>\n      <td>Coal Electric Power Sector CO2 Emissions</td>\n      <td>Million Metric Tons of Carbon Dioxide</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>CLEIEUS</td>\n      <td>197304</td>\n      <td>60.842</td>\n      <td>1</td>\n      <td>Coal Electric Power Sector CO2 Emissions</td>\n      <td>Million Metric Tons of Carbon Dioxide</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>CLEIEUS</td>\n      <td>197305</td>\n      <td>61.798</td>\n      <td>1</td>\n      <td>Coal Electric Power Sector CO2 Emissions</td>\n      <td>Million Metric Tons of Carbon Dioxide</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('./data/carbon_original.csv')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.543394Z",
     "end_time": "2025-02-09T20:52:57.559094Z"
    }
   },
   "outputs": [],
   "source": [
    "use_data = data[data['MSN']=='CLEIEUS'].iloc[:,[2]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "       Value\n0     72.076\n1     64.442\n2     64.084\n3     60.842\n4     61.798\n..       ...\n561    72.84\n562    71.41\n563    82.51\n564  115.772\n565  135.958\n\n[566 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Value</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>72.076</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>64.442</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>64.084</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>60.842</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>61.798</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>561</th>\n      <td>72.84</td>\n    </tr>\n    <tr>\n      <th>562</th>\n      <td>71.41</td>\n    </tr>\n    <tr>\n      <th>563</th>\n      <td>82.51</td>\n    </tr>\n    <tr>\n      <th>564</th>\n      <td>115.772</td>\n    </tr>\n    <tr>\n      <th>565</th>\n      <td>135.958</td>\n    </tr>\n  </tbody>\n</table>\n<p>566 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "use_data"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.546122Z",
     "end_time": "2025-02-09T20:52:57.559094Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.553791Z",
     "end_time": "2025-02-09T20:52:57.559094Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.556321Z",
     "end_time": "2025-02-09T20:52:57.560093Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\liuhao\\AppData\\Local\\Temp\\ipykernel_17444\\217526566.py:2: FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead.\n",
      "  dates = pd.date_range(start='2022-01-01', periods=566, freq='H')\n"
     ]
    }
   ],
   "source": [
    "# 生成日期范围（484天）\n",
    "dates = pd.date_range(start='2022-01-01', periods=566, freq='H')\n",
    "dates=pd.DataFrame(dates, columns=['date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [],
   "source": [
    "date_data=pd.concat([dates,use_data],axis=1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.561164Z",
     "end_time": "2025-02-09T20:52:57.565207Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [],
   "source": [
    "# 将 'Value' 列转换为 float 类型\n",
    "date_data['Value'] = date_data['Value'].astype(float)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.565207Z",
     "end_time": "2025-02-09T20:52:57.569128Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.569508Z",
     "end_time": "2025-02-09T20:52:57.675345Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 1000x600 with 1 Axes>",
      "image/png": "[encoded data, 113052 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制第二列的图像\n",
    "plt.figure(figsize=(10, 6))\n",
    "plt.plot(date_data.index, date_data['Value'], label='Value')\n",
    "plt.xlabel('Date')\n",
    "plt.ylabel('Value')\n",
    "plt.title('Time Series Plot of Second Column')\n",
    "plt.legend()\n",
    "plt.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.666305Z",
     "end_time": "2025-02-09T20:52:57.675345Z"
    }
   },
   "outputs": [],
   "source": [
    "date_data.to_csv('data/carbon_data_hourly.csv', index=False, encoding='utf-8-sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2025-02-09T20:52:57.670401Z",
     "end_time": "2025-02-09T20:52:57.675898Z"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py39",
   "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.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
