DA

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(bar)
(时序数据分析)
第56行: 第56行:
  
 
* [https://www.jianshu.com/p/b91e3ae940ec pandas 日期处理]
 
* [https://www.jianshu.com/p/b91e3ae940ec pandas 日期处理]
 +
 +
<source lang=python>
 +
>>> x = pd.date_range('2020-1-9','2020-2-15',freq='1d')
 +
>>> print(x)
 +
DatetimeIndex(['2020-01-09', '2020-01-10', '2020-01-11', '2020-01-12',
 +
              '2020-01-13', '2020-01-14', '2020-01-15', '2020-01-16',
 +
              '2020-01-17', '2020-01-18', '2020-01-19', '2020-01-20',
 +
              '2020-01-21', '2020-01-22', '2020-01-23', '2020-01-24',
 +
              '2020-01-25', '2020-01-26', '2020-01-27', '2020-01-28',
 +
              '2020-01-29', '2020-01-30', '2020-01-31', '2020-02-01',
 +
              '2020-02-02', '2020-02-03', '2020-02-04', '2020-02-05',
 +
              '2020-02-06', '2020-02-07', '2020-02-08', '2020-02-09',
 +
              '2020-02-10', '2020-02-11', '2020-02-12', '2020-02-13',
 +
              '2020-02-14', '2020-02-15'],
 +
              dtype='datetime64[ns]', freq='D')
 +
</source>
  
 
<br>
 
<br>

2020年2月16日 (日) 20:13的版本

目录

1 Overview


2 描述性统计


3 探索数据分布

3.1 bar

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdate

hb = pd.read_csv("../DA/data/ncp-hb-new.csv", index_col='Date', parse_dates=True, skipinitialspace=True)
cn = pd.read_csv("../DA/data/ncp-cn-new.csv", index_col='Date', parse_dates=True, skipinitialspace=True)
xhb = cn-hb
plt.gca().xaxis.set_major_formatter(mdate.DateFormatter('%m-%d'))
#plt.bar(hb.index, hb['Confirmed'].values)
plt.bar(xhb.index, xhb['Confirmed'].values)
plt.show()

同时显示湖北和非湖北柱状图:

plt.bar(hb.index, hb['Confirmed'].values, align='edge', width=-0.4)
plt.bar(xhb.index, xhb_cf, align='edge', width=0.4)
plt.show()


4 时序数据分析

>>> x = pd.date_range('2020-1-9','2020-2-15',freq='1d')
>>> print(x)
DatetimeIndex(['2020-01-09', '2020-01-10', '2020-01-11', '2020-01-12',
               '2020-01-13', '2020-01-14', '2020-01-15', '2020-01-16',
               '2020-01-17', '2020-01-18', '2020-01-19', '2020-01-20',
               '2020-01-21', '2020-01-22', '2020-01-23', '2020-01-24',
               '2020-01-25', '2020-01-26', '2020-01-27', '2020-01-28',
               '2020-01-29', '2020-01-30', '2020-01-31', '2020-02-01',
               '2020-02-02', '2020-02-03', '2020-02-04', '2020-02-05',
               '2020-02-06', '2020-02-07', '2020-02-08', '2020-02-09',
               '2020-02-10', '2020-02-11', '2020-02-12', '2020-02-13',
               '2020-02-14', '2020-02-15'],
              dtype='datetime64[ns]', freq='D')


5 Reference





个人工具
名字空间

变换
操作
导航
工具箱