q=pd.Series([7,8,9,10,11,12,13,14,15])print(q)
a={string.ascii_uppercase[i]:i for i inrange(10)}print(pd.Series(a))print(pd.Series(a,index=list(string.ascii_uppercase[3:13])))
t=pd.Series(np.arange(10),index=list(string.ascii_uppercase[:10]))print(t)
# coding:utf-8import pandas as pd
from matplotlib import pylab as p
file_path ="F:\directory.csv"#读取DateFrame对象
df = pd.read_csv(file_path)#排序
num_data = df.groupby(by="Country").count()["Brand"].sort_values(ascending=False)[:10]
_x = num_data.index
_y = num_data.values
p.bar(range(len(_x)), _y, width=0.3)
p.xticks(range(len(_x)), _x)
p.show()
使用matplotlib呈现中国每个城市的店铺数量
#coding:utf-8import pandas as pd
from matplotlib import pylab as p
from matplotlib import font_manager
#字体
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simkai.ttf")
file_path ="F:\directory.csv"#读出DateFrame对象
df = pd.read_csv(file_path)
data = df.groupby(by=["Country","City"])["Brand"].count()#按降序排序
num_data = data["CN"].sort_values(ascending=False)[:40]
_x = num_data.values
_y = num_data.index
p.figure(figsize=(15,10),dpi=80)
p.barh(range(len(_y)),_x,height=0.4)
p.yticks(range(len(_y)),_y,fontproperties=my_font)
p.grid()
p.show()
统计不同年份书的数量
#coding:utf-8import pandas as pd
from matplotlib import pylab as p
from matplotlib import font_manager
#字体
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simkai.ttf")
file_path ="F:/books.csv"
df = pd.read_csv(file_path)#降序排序
data = df["books_count"].groupby(by=df["original_publication_year"]).sum().sort_values(ascending=False)
x = data.index
y = data.values
#设置图片参数
p.figure(figsize=(15,8),dpi=80)
p.scatter()
p.show()
统计不同年份书的平均评分情况
#coding:utf-8import pandas as pd
from matplotlib import pylab as p
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simkai.ttf")
file_path ="F:/books.csv"
df = pd.read_csv(file_path)
data = df.groupby(by="original_publication_year")["average_rating"].mean()
_x = data.index
_y = data.values
p.figure(figsize=(15,8),dpi=80)
p.plot(range(len(_x)),_y)
p.xticks(list(range(len(_x)))[::10],_x[::10].astype(int),rotation=45)
p.show()
统计911不同类型的紧急情况的次数
#coding:utf-8import numpy as np
import pandas as pd
from matplotlib import pylab as p
from matplotlib import font_manager
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simkai.ttf")
file_path ="F:\911.csv"
df = pd.read_csv(file_path)
temp_list = df["title"].str.split(":").tolist()
data_list =list(set([i[0]for i in temp_list]))
zero_df = pd.DataFrame(np.zeros((df.shape[0],len(data_list))),columns=data_list)for i in data_list:
zero_df[i][df["title"].str.contains(i)]=1
type_count = zero_df.sum(axis=0)print(type_count)
_x = type_count.index
_y = type_count.values
p.figure(figsize=(15,8),dpi=80)
p.bar(_x,_y,width=0.1)
p.show()
北京PM2.5数据
#coding:utf-8import pandas as pd
import pylab as p
file_path ="F:/BeijingPM20100101_20151231.csv"
df = pd.read_csv(file_path)
period = pd.PeriodIndex(year=df["year"],month=df["month"],day=df["day"],hour=df["hour"],freq="H")
df["datetime"]= period
df.set_index("datetime",inplace=True)
df = df.resample("10D").mean()
data = df["PM_US Post"].dropna()
data_chain = df["PM_Dongsi"].dropna()
x=data.index
x=[i.strftime("%Y%m%d")for i in x]
x_chain =[i.strftime("%Y%m%d")for i in data_chain.index]
y=data.values
y_chain = data_chain.values
p.figure(figsize=(15,8),dpi=80)
p.plot(range(len(x)),y,label="US")
p.plot(range(len(x_chain)),y_chain,label="CN")
p.xticks(range(0,len(x),10),list(x)[::10],rotation=45)
p.legend()
p.show()