博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
吴裕雄 python 数据处理(1)
阅读量:5228 次
发布时间:2019-06-14

本文共 8497 字,大约阅读时间需要 28 分钟。

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)

 

转载于:https://www.cnblogs.com/tszr/p/10075889.html

你可能感兴趣的文章
系统的横向结构(AOP)
查看>>
linux常用命令
查看>>
NHibernate.3.0.Cookbook第四章第6节的翻译
查看>>
使用shared memory 计算矩阵乘法 (其实并没有加速多少)
查看>>
Django 相关
查看>>
git init
查看>>
训练记录
查看>>
IList和DataSet性能差别 转自 http://blog.csdn.net/ilovemsdn/article/details/2954335
查看>>
Hive教程(1)
查看>>
第16周总结
查看>>
C#编程时应注意的性能处理
查看>>
Fragment
查看>>
比较安全的获取站点更目录
查看>>
苹果开发者账号那些事儿(二)
查看>>
使用C#交互快速生成代码!
查看>>
UVA11374 Airport Express
查看>>
P1373 小a和uim之大逃离 四维dp,维护差值
查看>>
NOIP2015 运输计划 树上差分+树剖
查看>>
P3950 部落冲突 树链剖分
查看>>
读书_2019年
查看>>