1. 程式人生 > >吳裕雄 python 數據處理(1)

吳裕雄 python 數據處理(1)

amp groupby http port enc nco img value print

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)