码迷,mamicode.com
首页 > 编程语言 > 详细

吴裕雄 python 数据处理(1)

时间:2018-12-06 14:25:17      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:reduce   iter   otl   clu   join   技术   outer   显示   show   

import time

print(time.time())
print(time.localtime())
print(time.strftime(‘%Y-%m-%d %X‘,time.localtime()))

技术分享图片

绘图显示中文配置

技术分享图片

技术分享图片

import matplotlib.pyplot as plt

a = [1,1,2,3]
b = [2,2,2,2]
plt.plot(a,b)
plt.title("天生自然")
plt.show()

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv")
print(df.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
df.to_csv("E:\\temp\\taobao_price_data.csv", columns=["宝贝","价格"],index=False,header=True)

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df[0:3])

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
cols = df[["宝贝","价格"]]
print(cols.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.ix[0:3,["宝贝","价格"]]
print(a)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
df["销售量"] = df["价格"]*df["成交量"]
print(df.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[(df["价格"]<100)&(df["成交量"]<10000)]
print(a)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df.head())
df1 = df.set_index("位置")
print(df1.head())
df2 = df1.sort_index()
print(df2.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
df1 = df.set_index(["位置","卖家"])
print(df1.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
df1 = df.set_index(["位置","卖家"]).sortlevel(0)
print(df1.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.drop(["宝贝","卖家"],axis=1)
print(a.head())

b = df.drop(["宝贝","卖家"],axis=1).groupby("位置")
print(b.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.drop(["宝贝","卖家"],axis=1).groupby("位置").mean()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.drop(["宝贝","卖家"],axis=1).groupby("位置").mean().sort_values("成交量",ascending=False)
print(a.head())

 技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.drop(["宝贝","卖家"],axis=1).groupby("位置").sum().sort_values("成交量",ascending=False)
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df.info())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df.describe())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
print(df.describe(include=["object"]))

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df["成交量"].groupby(df["位置"])
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df["成交量"].groupby(df["位置"]).mean()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df["成交量"].groupby([df["位置"],df["卖家"]]).mean()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.groupby("位置").mean()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.groupby(["位置","卖家"]).mean()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df.groupby(["位置","卖家"]).size()
print(a.head())

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[30:35][["位置","卖家"]]
print(a)

b = df[90:95][["卖家","成交量"]]
print(b)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[30:35][["位置","卖家"]]
b = df[30:35][["卖家","成交量"]]
c = pd.merge(a,b)
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[30:35][["位置","卖家"]]
b = df[30:35][["卖家","成交量"]]
c = pd.merge(a,b,on="卖家")
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[10:20][["位置","卖家"]]
b = df[30:40][["卖家","成交量"]]
c = pd.merge(a,b,how="outer")
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[10:20][["位置","卖家"]]
b = df[30:40][["卖家","成交量"]]
c = pd.merge(a,b,how="left")
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[10:20][["位置","卖家"]]
b = df[30:40][["卖家","成交量"]]
c = pd.merge(a,b,how="right")
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:10][["位置","卖家"]]
print(a)
b = df[:10][["卖家","成交量"]]
print(b)
c = pd.merge(a,b,how="right")
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:10][["位置","卖家"]]
b = df[:10][["卖家","成交量"]]
c = pd.merge(a,b,left_index=True,right_index=True)
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:10][["位置","卖家"]]
b = df[:10][["价格","成交量"]]
c = pd.merge(a,b,left_index=True,right_index=True)
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:10][["位置","卖家"]]
b = df[:10][["价格","成交量"]]
c = a.join(b)
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:5]["宝贝"]
b = df[5:10]["宝贝"]
c = df[10:15]["宝贝"]
d = pd.concat([a,b,c])
print(d)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:5]["宝贝"]
print(a)
b = df[:5]["价格"]
print(b)
c = df[:5]["成交量"]
print(c)
d = pd.concat([a,b,c],axis=1)
print(d)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:5][["位置","卖家"]]
print(a)
b = df[:5][["价格","成交量"]]
print(b)
c = pd.concat([a,b])
print(c)

技术分享图片

import pandas as pd

df = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\taobao_data.csv",delimiter=",",encoding="utf8",header=0)
a = df[:5][["位置","卖家"]]
print(a)
b = df[:5][["价格","成交量"]]
print(b)
c = pd.concat([a,b],axis=1)
print(c)

技术分享图片

 

吴裕雄 python 数据处理(1)

标签:reduce   iter   otl   clu   join   技术   outer   显示   show   

原文地址:https://www.cnblogs.com/tszr/p/10075889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!