119 KiB
119 KiB
In [63]:
import pandas as pd import numpy as np import matplotlib.pyplot as plt
In [64]:
data = pd.read_csv('./data/carbon_original.csv') data.head()
Out[64]:
MSN | YYYYMM | Value | Column_Order | Description | Unit | |
---|---|---|---|---|---|---|
0 | CLEIEUS | 197301 | 72.076 | 1 | Coal Electric Power Sector CO2 Emissions | Million Metric Tons of Carbon Dioxide |
1 | CLEIEUS | 197302 | 64.442 | 1 | Coal Electric Power Sector CO2 Emissions | Million Metric Tons of Carbon Dioxide |
2 | CLEIEUS | 197303 | 64.084 | 1 | Coal Electric Power Sector CO2 Emissions | Million Metric Tons of Carbon Dioxide |
3 | CLEIEUS | 197304 | 60.842 | 1 | Coal Electric Power Sector CO2 Emissions | Million Metric Tons of Carbon Dioxide |
4 | CLEIEUS | 197305 | 61.798 | 1 | Coal Electric Power Sector CO2 Emissions | Million Metric Tons of Carbon Dioxide |
In [65]:
use_data = data[data['MSN']=='CLEIEUS'].iloc[:,[2]]
In [66]:
use_data
Out[66]:
Value | |
---|---|
0 | 72.076 |
1 | 64.442 |
2 | 64.084 |
3 | 60.842 |
4 | 61.798 |
... | ... |
561 | 72.84 |
562 | 71.41 |
563 | 82.51 |
564 | 115.772 |
565 | 135.958 |
566 rows × 1 columns
In [66]:
In [67]:
# 生成日期范围(484天) dates = pd.date_range(start='2022-01-01', periods=566, freq='H') dates=pd.DataFrame(dates, columns=['date'])
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. dates = pd.date_range(start='2022-01-01', periods=566, freq='H')
In [68]:
date_data=pd.concat([dates,use_data],axis=1)
In [69]:
# 将 'Value' 列转换为 float 类型 date_data['Value'] = date_data['Value'].astype(float)
In [70]:
# 绘制第二列的图像 plt.figure(figsize=(10, 6)) plt.plot(date_data.index, date_data['Value'], label='Value') plt.xlabel('Date') plt.ylabel('Value') plt.title('Time Series Plot of Second Column') plt.legend() plt.grid(True) plt.show()
In [71]:
date_data.to_csv('data/carbon_data_hourly.csv', index=False, encoding='utf-8-sig')
In [71]: