written in front of the words:
All of the data in the instance is downloaded from the GitHub and packaged for download.
The address is: Http://github.com/pydata/pydata-book there are certain to be explained:
I'm using Python2.7, the code in the book has some bugs, and I use my 2.7 version to tune in.
# Coding:utf-8 from pandas import Series, dataframe import pandas as PD import NumPy as NP df = pd.read_csv (' D:\Source C
Ode\pydata-book-master\ch06\ex1.csv ') DF pd.read_table (' D:\Source code\pydata-book-master\ch06\ex1.csv ', sep= ', ') Pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex2.csv ', Header=none) pd.read_csv (' D:\Source code\ Pydata-book-master\ch06\ex2.csv ', names=[' a ', ' B ', ' C ', ' d ', ' message ']) names=[' A ', ' B ', ' C ', ' d ', ' message '] Pd.read_ CSV (' D:\Source code\pydata-book-master\ch06\ex2.csv ', names=names, index_col = ' message ') parsed = pd.read_csv (' D:\ Source code\pydata-book-master\ch06\csv_mindex.csv ', index_col = [' Key1 ', ' Key2 ']) List (open (' D:\Source code\ Pydata-book-master\ch06\ex3.txt ') result = pd.read_table (' D:\Source code\pydata-book-master\ch06\ex3.txt ', sep= ' \s + ') result pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex4.csv ', skiprows=[0,2,3]) result = Pd.read_csv (' D:\ Source code\pydata-book-master\ch06\ex5.csv ') result pd.isnull [result] result = Pd.read_csv(' D:\Source code\pydata-book-master\ch06\ex5.csv ', na_values=[' NULL ']) Result sentinels = {' message ': [' foo ', ' na '], ' Something ': [' two ']} pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex5.csv ', na_values = sentinels) result = Pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex6.csv ') result Pd.read_csv (' D:\Source code\ Pydata-book-master\ch06\ex6.csv ', nrows=5) Chunker = Pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex6.csv ', chunksize=1000) Chunker tot = Series ([]) for piece in Chunker:tot = Tot.add (piece[' key '].value_counts (), fill_value=0 ) tot = Tot.order (ascending=false) tot[:10] data = pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex5.csv ') Data da Ta.to_csv (' D:\out.csv ') pd.read_csv (' D:\out.csv ') import sys data.to_csv (sys.stdout, sep= ' | ') Data.to_csv (sys.stdout , na_rep= ' NULL ') data.to_csv (Sys.stdout, Index=false, Header=false) data.to_csv (Sys.stdout, Index=false, cols=[' a ', ' B ', ' C ']) dates = Pd.date_range (' 1/1/2000 ', periods=7) ts = Series (Np.arange (7), Index=dates) ts.to_csv (' D:\out.csv ') series.from_csv (' D:\out.csv ', parse_dates=true) import csv f = open (' D:\Source code\ Pydata-book-master\ch06\ex7.csv ') reader = Csv.reader (f) for line in Reader:print line lines = List (Csv.reader open (' D:\Source code\pydata-book-master\ch06\ex7.csv ')) Header,values = line[0],lines[1:] data_dict = {h:v for h, v in Zip (head Er,zip (*values))} data_dict import json obj = "" "{Names": "Www0", "Places": ["AA", "BB", "CC", "DD"], "pet": null, "siblings
': [{' Name ': ' Wang ', ' Age ': ' Zuko '},{' name ': ' Zhang ', ' age ':, ' pet ': ' Cisco '}]} ' ' result = json.loads (obj) Result Asjson = Json.dumps (result) Asjson siblings = Dataframe (result[' siblings '],columns=[' name ', ' age ']) siblings from Lxml.html Import parse from urllib2 import urlopen parsed = Parse (Urlopen (' http://finance.yahoo.com/q/op?s=AAPL+ Options ')) doc = Parsed.getroot () from lxml import objectify path = ' D:\Source code\pydata-book-master\ch06\mta_perf\perf
Ormance_mnr.xml ' parsed = objectify.parse (open (path))root = Parsed.getroot () data = [] for ELT in root. Indicator:el_data = {} for child in Elt.getchildren (): El_data[child.tag] = Child.pyval Data.append (E L_data) perf = dataframe (data) perf frame = pd.read_csv (' D:\Source code\pydata-book-master\ch06\ex1.csv ') frame frame.sa ve (' D:\Source code\pydata-book-master\ch06\\aa ') frame.load (' D:\Source code\pydata-book-master\ch06\\aa ') import
Requests url = ' http://gc.ditu.aliyun.com/regeocoding?l=39.938133,116.395739&type=001 ' resp = requests.get (URL) RESP data = json.loads (Resp.text)