import csv
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from matplotlib.pylab import date2num
import datetime
csvFile=open('F:user(2).csv');
reader=csv.reader(csvFile)
arr=[]
register={}# 注册日期,数量
#fig, ax = plt.subplots(figsize=(15,5))
plt.grid(True)
# 设置日期刻度旋转的角度
plt.xticks(rotation=30)
plt.title('register count')
plt.xlabel('Date')
plt.ylabel('count')
# x轴的刻度为日期
ax.xaxis_date()
for item in reader:
if item[0]!="0000-0-0 00:00:00":
arr.append(datetime.datetime.strptime(item[0], "%Y-%m-%d %H:%M:%S").strftime('%Y-%m'))
for i in arr:
if i not in register:
register[i]=1
else:
register[i]+=1
date=[]
for key in register:
x = key
y = register[key]
#print(y)
date_time = datetime.datetime.strptime(key,'%Y-%m')
plt.plot_date(date_time,y,'-',color='b',marker = 'o',markersize = '14.5')
plt.show()