第二章 数据科学的编程工具

Python使用简介

王成军

人生苦短,我用Python。

Python(/ˈpaɪθən/)是一种面向对象、解释型计算机程序设计语言

  • 由Guido van Rossum于1989年底发明

  • 第一个公开发行版发行于1991年

  • Python语法简洁而清晰

  • 具有强大的标准库和丰富的第三方模块

  • 它常被昵称为胶水语言

  • TIOBE编程语言排行榜“2010年度编程语言”

特点

  • 免费、功能强大、使用者众多

  • 与R和MATLAB相比,Python是一门更易学、更严谨的程序设计语言。使用Python编写的脚本更易于理解和维护。

  • 如同其它编程语言一样,Python语言的基础知识包括:类型、列表(list)和元组(tuple)、字典(dictionary)、条件、循环、异常处理等。

  • 关于这些,初阶读者可以阅读《Beginning Python》一书(Hetland, 2005)。

Python中包含了丰富的类库。

众多开源的科学计算软件包都提供了Python的调用接口,例如著名的计算机视觉库OpenCV。 Python本身的科学计算类库发展也十分完善,例如NumPy、SciPy和matplotlib等。 就社会网络分析而言,igraph, networkx, graph-tool, Snap.py等类库提供了丰富的网络分析工具

Python软件与IDE

目前最新的Python版本为3.0,更稳定的2.7版本。 编译器是编写程序的重要工具。 免费的Python编译器有Spyder、PyCharm(免费社区版)、Ipython、Vim、 Emacs、 Eclipse(加上PyDev插件)。

Installing Anaconda Python

  • Use the Anaconda Python

    • http://anaconda.com/

第三方包可以使用pip install的方法安装。

  • 可以点击ToolsOpen command prompt

  • 然后在打开的命令窗口中输入:

    • pip install beautifulsoup4

pip install beautifulsoup4

  • NumPy /SciPy for scientific computing

  • pandas to make Python usable for data analysis

  • matplotlib to make graphics

  • scikit-learn for machine learning

pip install flownetwork
Processing /Users/datalab/Library/Caches/pip/wheels/87/32/ba/7ba0070ffcd371ae5c13511b55583e01b080cb05bcad4dc443/flownetwork-3.1.0-py2.py3-none-any.whl
Collecting peppercorn
  Using cached peppercorn-0.6-py3-none-any.whl (4.8 kB)
Installing collected packages: peppercorn, flownetwork
Successfully installed flownetwork-3.1.0 peppercorn-0.6
Note: you may need to restart the kernel to use updated packages.
from flownetwork import flownetwork as fn
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

print(fn.__version__)
$version = py3.0.1$
help(fn.constructFlowNetwork)
Help on function constructFlowNetwork in module flownetwork.flownetwork:

constructFlowNetwork(C)
    C is an array of two dimentions, e.g., 
    C = np.array([[user1, item1], 
                  [user1, item2], 
                  [user2, item1], 
                  [user2, item3]])
    Return a balanced flow network
# constructing a flow network
demo = fn.attention_data
gd = fn.constructFlowNetwork(demo)
# drawing a demo network
fig = plt.figure(figsize=(12, 8),facecolor='white')
pos={0: np.array([ 0.2 ,  0.8]),
 2: np.array([ 0.2,  0.2]),
 1: np.array([ 0.4,  0.6]),
 6: np.array([ 0.4,  0.4]),
 4: np.array([ 0.7,  0.8]),
 5: np.array([ 0.7,  0.5]),
 3: np.array([ 0.7,  0.2 ]),
 'sink': np.array([ 1,  0.5]),
 'source': np.array([ 0,  0.5])}

width=[float(d['weight']*1.2) for (u,v,d) in gd.edges(data=True)]
edge_labels=dict([((u,v,),d['weight']) for u,v,d in gd.edges(data=True)])

nx.draw_networkx_edge_labels(gd,pos,edge_labels=edge_labels, font_size = 15, alpha = .5)
nx.draw(gd, pos, node_size = 3000, node_color = 'orange',
        alpha = 0.2, width = width, edge_color='orange',style='solid')
nx.draw_networkx_labels(gd,pos,font_size=18)
plt.show()
_images/03-python-intro_13_0.png
nx.info(gd)
'Name: \nType: DiGraph\nNumber of nodes: 9\nNumber of edges: 15\nAverage in degree:   1.6667\nAverage out degree:   1.6667'
# flow matrix
m = fn.getFlowMatrix(gd)
m
matrix([[0., 5., 1., 0., 2., 1., 0., 0., 0.],
        [0., 0., 0., 0., 1., 0., 0., 3., 1.],
        [0., 0., 0., 1., 0., 0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 3., 0., 0., 0.],
        [0., 0., 0., 2., 0., 0., 2., 0., 0.],
        [0., 0., 0., 2., 0., 0., 0., 0., 0.],
        [0., 0., 0., 2., 0., 0., 0., 0., 1.],
        [0., 0., 0., 2., 0., 0., 0., 0., 0.]])
fn.networkDissipate(gd)
defaultdict(<function flownetwork.flownetwork.networkDissipate.<locals>.<lambda>()>,
            {0: [0, 5, 5],
             1: [0, 3, 2],
             2: [2, 4, 1],
             6: [1, 1, 1],
             3: [2, 2, 0],
             4: [2, 3, 0],
             5: [2, 2, 0]})
%matplotlib inline
import random, datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import statsmodels.api as sm
from scipy.stats import norm
from scipy.stats.stats import pearsonr

Variable Type

# str, int, float, bool
str(3)
'3'
"chengjun wang"
'chengjun wang'
# int
int('5') 
5
# float
float('7.1')
7.1
range(10)
range(0, 10)
# for i in range(1, 10):
#     print(i)

range(1,10) 
range(1, 10)

dir & help

当你想要了解对象的详细信息时使用

dir(str)
['__add__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getitem__',
 '__getnewargs__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__iter__',
 '__le__',
 '__len__',
 '__lt__',
 '__mod__',
 '__mul__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__rmod__',
 '__rmul__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'capitalize',
 'casefold',
 'center',
 'count',
 'encode',
 'endswith',
 'expandtabs',
 'find',
 'format',
 'format_map',
 'index',
 'isalnum',
 'isalpha',
 'isascii',
 'isdecimal',
 'isdigit',
 'isidentifier',
 'islower',
 'isnumeric',
 'isprintable',
 'isspace',
 'istitle',
 'isupper',
 'join',
 'ljust',
 'lower',
 'lstrip',
 'maketrans',
 'partition',
 'replace',
 'rfind',
 'rindex',
 'rjust',
 'rpartition',
 'rsplit',
 'rstrip',
 'split',
 'splitlines',
 'startswith',
 'strip',
 'swapcase',
 'title',
 'translate',
 'upper',
 'zfill']
'cheng'.capitalize()
'Cheng'
dir(str)[-10:]
['rstrip',
 'split',
 'splitlines',
 'startswith',
 'strip',
 'swapcase',
 'title',
 'translate',
 'upper',
 'zfill']
help(str)
Help on class str in module builtins:

class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |  
 |  Create a new string object from the given object. If encoding or
 |  errors is specified, then the object must expose a data buffer
 |  that will be decoded using the given encoding and error handler.
 |  Otherwise, returns the result of object.__str__() (if defined)
 |  or repr(object).
 |  encoding defaults to sys.getdefaultencoding().
 |  errors defaults to 'strict'.
 |  
 |  Methods defined here:
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __format__(self, format_spec, /)
 |      Return a formatted version of the string as described by format_spec.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __getitem__(self, key, /)
 |      Return self[key].
 |  
 |  __getnewargs__(...)
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __hash__(self, /)
 |      Return hash(self).
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __len__(self, /)
 |      Return len(self).
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __mod__(self, value, /)
 |      Return self%value.
 |  
 |  __mul__(self, value, /)
 |      Return self*value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __rmod__(self, value, /)
 |      Return value%self.
 |  
 |  __rmul__(self, value, /)
 |      Return value*self.
 |  
 |  __sizeof__(self, /)
 |      Return the size of the string in memory, in bytes.
 |  
 |  __str__(self, /)
 |      Return str(self).
 |  
 |  capitalize(self, /)
 |      Return a capitalized version of the string.
 |      
 |      More specifically, make the first character have upper case and the rest lower
 |      case.
 |  
 |  casefold(self, /)
 |      Return a version of the string suitable for caseless comparisons.
 |  
 |  center(self, width, fillchar=' ', /)
 |      Return a centered string of length width.
 |      
 |      Padding is done using the specified fill character (default is a space).
 |  
 |  count(...)
 |      S.count(sub[, start[, end]]) -> int
 |      
 |      Return the number of non-overlapping occurrences of substring sub in
 |      string S[start:end].  Optional arguments start and end are
 |      interpreted as in slice notation.
 |  
 |  encode(self, /, encoding='utf-8', errors='strict')
 |      Encode the string using the codec registered for encoding.
 |      
 |      encoding
 |        The encoding in which to encode the string.
 |      errors
 |        The error handling scheme to use for encoding errors.
 |        The default is 'strict' meaning that encoding errors raise a
 |        UnicodeEncodeError.  Other possible values are 'ignore', 'replace' and
 |        'xmlcharrefreplace' as well as any other name registered with
 |        codecs.register_error that can handle UnicodeEncodeErrors.
 |  
 |  endswith(...)
 |      S.endswith(suffix[, start[, end]]) -> bool
 |      
 |      Return True if S ends with the specified suffix, False otherwise.
 |      With optional start, test S beginning at that position.
 |      With optional end, stop comparing S at that position.
 |      suffix can also be a tuple of strings to try.
 |  
 |  expandtabs(self, /, tabsize=8)
 |      Return a copy where all tab characters are expanded using spaces.
 |      
 |      If tabsize is not given, a tab size of 8 characters is assumed.
 |  
 |  find(...)
 |      S.find(sub[, start[, end]]) -> int
 |      
 |      Return the lowest index in S where substring sub is found,
 |      such that sub is contained within S[start:end].  Optional
 |      arguments start and end are interpreted as in slice notation.
 |      
 |      Return -1 on failure.
 |  
 |  format(...)
 |      S.format(*args, **kwargs) -> str
 |      
 |      Return a formatted version of S, using substitutions from args and kwargs.
 |      The substitutions are identified by braces ('{' and '}').
 |  
 |  format_map(...)
 |      S.format_map(mapping) -> str
 |      
 |      Return a formatted version of S, using substitutions from mapping.
 |      The substitutions are identified by braces ('{' and '}').
 |  
 |  index(...)
 |      S.index(sub[, start[, end]]) -> int
 |      
 |      Return the lowest index in S where substring sub is found, 
 |      such that sub is contained within S[start:end].  Optional
 |      arguments start and end are interpreted as in slice notation.
 |      
 |      Raises ValueError when the substring is not found.
 |  
 |  isalnum(self, /)
 |      Return True if the string is an alpha-numeric string, False otherwise.
 |      
 |      A string is alpha-numeric if all characters in the string are alpha-numeric and
 |      there is at least one character in the string.
 |  
 |  isalpha(self, /)
 |      Return True if the string is an alphabetic string, False otherwise.
 |      
 |      A string is alphabetic if all characters in the string are alphabetic and there
 |      is at least one character in the string.
 |  
 |  isascii(self, /)
 |      Return True if all characters in the string are ASCII, False otherwise.
 |      
 |      ASCII characters have code points in the range U+0000-U+007F.
 |      Empty string is ASCII too.
 |  
 |  isdecimal(self, /)
 |      Return True if the string is a decimal string, False otherwise.
 |      
 |      A string is a decimal string if all characters in the string are decimal and
 |      there is at least one character in the string.
 |  
 |  isdigit(self, /)
 |      Return True if the string is a digit string, False otherwise.
 |      
 |      A string is a digit string if all characters in the string are digits and there
 |      is at least one character in the string.
 |  
 |  isidentifier(self, /)
 |      Return True if the string is a valid Python identifier, False otherwise.
 |      
 |      Use keyword.iskeyword() to test for reserved identifiers such as "def" and
 |      "class".
 |  
 |  islower(self, /)
 |      Return True if the string is a lowercase string, False otherwise.
 |      
 |      A string is lowercase if all cased characters in the string are lowercase and
 |      there is at least one cased character in the string.
 |  
 |  isnumeric(self, /)
 |      Return True if the string is a numeric string, False otherwise.
 |      
 |      A string is numeric if all characters in the string are numeric and there is at
 |      least one character in the string.
 |  
 |  isprintable(self, /)
 |      Return True if the string is printable, False otherwise.
 |      
 |      A string is printable if all of its characters are considered printable in
 |      repr() or if it is empty.
 |  
 |  isspace(self, /)
 |      Return True if the string is a whitespace string, False otherwise.
 |      
 |      A string is whitespace if all characters in the string are whitespace and there
 |      is at least one character in the string.
 |  
 |  istitle(self, /)
 |      Return True if the string is a title-cased string, False otherwise.
 |      
 |      In a title-cased string, upper- and title-case characters may only
 |      follow uncased characters and lowercase characters only cased ones.
 |  
 |  isupper(self, /)
 |      Return True if the string is an uppercase string, False otherwise.
 |      
 |      A string is uppercase if all cased characters in the string are uppercase and
 |      there is at least one cased character in the string.
 |  
 |  join(self, iterable, /)
 |      Concatenate any number of strings.
 |      
 |      The string whose method is called is inserted in between each given string.
 |      The result is returned as a new string.
 |      
 |      Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
 |  
 |  ljust(self, width, fillchar=' ', /)
 |      Return a left-justified string of length width.
 |      
 |      Padding is done using the specified fill character (default is a space).
 |  
 |  lower(self, /)
 |      Return a copy of the string converted to lowercase.
 |  
 |  lstrip(self, chars=None, /)
 |      Return a copy of the string with leading whitespace removed.
 |      
 |      If chars is given and not None, remove characters in chars instead.
 |  
 |  partition(self, sep, /)
 |      Partition the string into three parts using the given separator.
 |      
 |      This will search for the separator in the string.  If the separator is found,
 |      returns a 3-tuple containing the part before the separator, the separator
 |      itself, and the part after it.
 |      
 |      If the separator is not found, returns a 3-tuple containing the original string
 |      and two empty strings.
 |  
 |  replace(self, old, new, count=-1, /)
 |      Return a copy with all occurrences of substring old replaced by new.
 |      
 |        count
 |          Maximum number of occurrences to replace.
 |          -1 (the default value) means replace all occurrences.
 |      
 |      If the optional argument count is given, only the first count occurrences are
 |      replaced.
 |  
 |  rfind(...)
 |      S.rfind(sub[, start[, end]]) -> int
 |      
 |      Return the highest index in S where substring sub is found,
 |      such that sub is contained within S[start:end].  Optional
 |      arguments start and end are interpreted as in slice notation.
 |      
 |      Return -1 on failure.
 |  
 |  rindex(...)
 |      S.rindex(sub[, start[, end]]) -> int
 |      
 |      Return the highest index in S where substring sub is found,
 |      such that sub is contained within S[start:end].  Optional
 |      arguments start and end are interpreted as in slice notation.
 |      
 |      Raises ValueError when the substring is not found.
 |  
 |  rjust(self, width, fillchar=' ', /)
 |      Return a right-justified string of length width.
 |      
 |      Padding is done using the specified fill character (default is a space).
 |  
 |  rpartition(self, sep, /)
 |      Partition the string into three parts using the given separator.
 |      
 |      This will search for the separator in the string, starting at the end. If
 |      the separator is found, returns a 3-tuple containing the part before the
 |      separator, the separator itself, and the part after it.
 |      
 |      If the separator is not found, returns a 3-tuple containing two empty strings
 |      and the original string.
 |  
 |  rsplit(self, /, sep=None, maxsplit=-1)
 |      Return a list of the words in the string, using sep as the delimiter string.
 |      
 |        sep
 |          The delimiter according which to split the string.
 |          None (the default value) means split according to any whitespace,
 |          and discard empty strings from the result.
 |        maxsplit
 |          Maximum number of splits to do.
 |          -1 (the default value) means no limit.
 |      
 |      Splits are done starting at the end of the string and working to the front.
 |  
 |  rstrip(self, chars=None, /)
 |      Return a copy of the string with trailing whitespace removed.
 |      
 |      If chars is given and not None, remove characters in chars instead.
 |  
 |  split(self, /, sep=None, maxsplit=-1)
 |      Return a list of the words in the string, using sep as the delimiter string.
 |      
 |      sep
 |        The delimiter according which to split the string.
 |        None (the default value) means split according to any whitespace,
 |        and discard empty strings from the result.
 |      maxsplit
 |        Maximum number of splits to do.
 |        -1 (the default value) means no limit.
 |  
 |  splitlines(self, /, keepends=False)
 |      Return a list of the lines in the string, breaking at line boundaries.
 |      
 |      Line breaks are not included in the resulting list unless keepends is given and
 |      true.
 |  
 |  startswith(...)
 |      S.startswith(prefix[, start[, end]]) -> bool
 |      
 |      Return True if S starts with the specified prefix, False otherwise.
 |      With optional start, test S beginning at that position.
 |      With optional end, stop comparing S at that position.
 |      prefix can also be a tuple of strings to try.
 |  
 |  strip(self, chars=None, /)
 |      Return a copy of the string with leading and trailing whitespace removed.
 |      
 |      If chars is given and not None, remove characters in chars instead.
 |  
 |  swapcase(self, /)
 |      Convert uppercase characters to lowercase and lowercase characters to uppercase.
 |  
 |  title(self, /)
 |      Return a version of the string where each word is titlecased.
 |      
 |      More specifically, words start with uppercased characters and all remaining
 |      cased characters have lower case.
 |  
 |  translate(self, table, /)
 |      Replace each character in the string using the given translation table.
 |      
 |        table
 |          Translation table, which must be a mapping of Unicode ordinals to
 |          Unicode ordinals, strings, or None.
 |      
 |      The table must implement lookup/indexing via __getitem__, for instance a
 |      dictionary or list.  If this operation raises LookupError, the character is
 |      left untouched.  Characters mapped to None are deleted.
 |  
 |  upper(self, /)
 |      Return a copy of the string converted to uppercase.
 |  
 |  zfill(self, width, /)
 |      Pad a numeric string with zeros on the left, to fill a field of the given width.
 |      
 |      The string is never truncated.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  maketrans(x, y=None, z=None, /)
 |      Return a translation table usable for str.translate().
 |      
 |      If there is only one argument, it must be a dictionary mapping Unicode
 |      ordinals (integers) or characters to Unicode ordinals, strings or None.
 |      Character keys will be then converted to ordinals.
 |      If there are two arguments, they must be strings of equal length, and
 |      in the resulting dictionary, each character in x will be mapped to the
 |      character at the same position in y. If there is a third argument, it
 |      must be a string, whose characters will be mapped to None in the result.
x = ' Hello WorlD  '
dir(x)[-10:] 
['rstrip',
 'split',
 'splitlines',
 'startswith',
 'strip',
 'swapcase',
 'title',
 'translate',
 'upper',
 'zfill']
# lower
x.lower() 
' hello world  '
# upper
x
' Hello WorlD  '
# rstrip
x.lstrip()
'Hello WorlD  '
# strip
x.strip()
'Hello WorlD'
# replace
x.replace('lo', '')
' Hel WorlD  '
# split
x.split('lo')
[' Hel', ' WorlD  ']
# join 
','.join(['a', 'b'])
'a,b'

type

当你想要了解变量类型时使用type

x = 'hello world'
type(x)
str

Data Structure

list, tuple, set, dictionary, array

l = [1,2,3,3] # list
t = (1, 2, 3, 3) # tuple
s = {1, 2, 3, 3} # set([1,2,3,3]) # set
d = {'a':1,'b':2,'c':3} # dict
a = np.array(l) # array
print(l, t, s, d, a)
[1, 2, 3, 3] (1, 2, 3, 3) {1, 2, 3} {'c': 3, 'b': 2, 'a': 1} [1 2 3 3]
l = [1,2,3,3] # list
l.append(4)
l
[1, 2, 3, 3, 4]
d = {'a':1,'b':2,'c':3} # dict
d.keys()
dict_keys(['a', 'b', 'c'])
d = {'a':1,'b':2,'c':3} # dict
d.values()
dict_values([1, 2, 3])
d = {'a':1,'b':2,'c':3} # dict
d['b']
2
d = {'a':1,'b':2,'c':3} # dict
d.items()
dict_items([('a', 1), ('b', 2), ('c', 3)])

定义函数

def devidePlus(m, n): # 结尾是冒号
    y = m/n + 1 # 注意:空格
    return y          # 注意:return

For 循环

range(10)
range(0, 10)
range(1, 10)  
range(1, 10)
for i in range(10):
    print(i, i*10, i**2)
0 0 0
1 10 1
2 20 4
3 30 9
4 40 16
5 50 25
6 60 36
7 70 49
8 80 64
9 90 81
for i in range(10):
    print(i*10) 
0
10
20
30
40
50
60
70
80
90
for i in range(10):
    print(devidePlus(i, 2))
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
# 列表内部的for循环
r = [devidePlus(i, 2)  for i in range(10)]
r 
[1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5]

map函数

def fahrenheit(T):
    return ((float(9)/5)*T + 32)

temp = [0, 22.5, 40,100]
F_temps = map(fahrenheit, temp)

print(*F_temps)
32.0 72.5 104.0 212.0
m1 = map(devidePlus, [4,3,2], [2, 1, 5])
print(*m1)
#print(*map(devidePlus, [4,3,2], [2, 1, 5]))
# 注意: 将(4, 2)作为一个组合进行计算,将(3, 1)作为一个组合进行计算
3.0 4.0 1.4
m2 = map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
print(*m2)
3 7 11 15 19
m3 = map(lambda x, y, z: x + y - z, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [3, 3, 2, 2, 5])
print(*m3)
0 4 9 13 14

if elif else

j = 5
if j%2 == 1:
    print(r'余数是1')
elif j%2 ==0:
    print(r'余数是0')
else:
    print(r'余数既不是1也不是0')
余数是1
x = 5
if x < 5:
    y = -1
    z = 5
elif x > 5:
    y = 1
    z = 11
else:
    y = 0
    z = 10
print(x, y, z)
5 0 10

while循环

j = 0
while j <10:
    print(j)
    j+=1 # avoid dead loop
    
0
1
2
3
4
5
6
7
8
9
j = 0
while j <10:
    if j%2 != 0: 
        print(j**2)
    j+=1 # avoid dead loop 
1
9
25
49
81
j = 0
while j <50:
    if j == 30:
        break
    if j%2 != 0: 
        print(j**2)
    j+=1 # avoid dead loop
    
1
9
25
49
81
121
169
225
289
361
441
529
625
729
841
a = 4
while a: # 0, None, False
    print(a) 
    a -= 1
    if a < 0:
        a = None # []
4
3
2
1

try except

def devidePlus(m, n): # 结尾是冒号
    return m/n+ 1 # 注意:空格


for i in [2, 0, 5]:
    try:
        print(devidePlus(4, i))
    except Exception as e:
        print(e)
        pass
3.0
division by zero
1.8
alist = [[1,1], [0, 0, 1]]
for aa in alist:
    try:
        for a in aa:
            print(10 / a)
    except Exception as e:
        print(e)
        pass
10.0
10.0
division by zero
alist = [[1,1], [0, 0, 1]]
for aa in alist:
    for a in aa:
        try:
            print(10 / a)
        except Exception as e:
            print(e)
            pass
10.0
10.0
division by zero
division by zero
10.0

Write and Read data

data =[[i, i**2, i**3] for i in range(10)] 
data
[[0, 0, 0],
 [1, 1, 1],
 [2, 4, 8],
 [3, 9, 27],
 [4, 16, 64],
 [5, 25, 125],
 [6, 36, 216],
 [7, 49, 343],
 [8, 64, 512],
 [9, 81, 729]]
for i in data:
    print('\t'.join(map(str, i)))  
0	0	0
1	1	1
2	4	8
3	9	27
4	16	64
5	25	125
6	36	216
7	49	343
8	64	512
9	81	729
type(data)
list
len(data)
10
data[0]
[0, 0, 0]
help(f.write)  
Help on built-in function write:

write(...)
    write(str) -> None.  Write string str to file.
    
    Note that due to buffering, flush() or close() may be needed before
    the file on disk reflects the data written.
# 保存数据
data =[[i, i**2, i**3] for i in range(10000)] 

f = open("../data/data_write_to_file1.txt", "w")
for i in data:
    f.write('\t'.join(map(str,i)) + '\n')
f.close()
with open('../data/data_write_to_file.txt','r') as f:
    data = f.readlines()
data[:5]
['0\t0\t0\n', '1\t1\t1\n', '2\t4\t8\n', '3\t9\t27\n', '4\t16\t64\n']
with open('../data/data_write_to_file.txt','r') as f:
    data = f.readlines(1000) #bytes 
len(data) 
459
with open('../data/data_write_to_file.txt','r') as f:
    print(f.readline())
0	0	0
f = [1, 2, 3, 4, 5]
for k, i in enumerate(f):
    print(k, i)
0 1
1 2
2 3
3 4
4 5
# with open('../data/data_write_to_file.txt','r') as f:
#     for i in f:
#         print(i)
with open('../data/data_write_to_file.txt','r') as f:
    for k, i in enumerate(f):
        if k%2000 == 0:
            print(i)
0	0	0

2000	4000000	8000000000

4000	16000000	64000000000

6000	36000000	216000000000

8000	64000000	512000000000
data = []
line = '0\t0\t0\n'
line = line.replace('\n', '')
line = line.split('\t')
line = [int(i) for i in line] # convert str to int
data.append(line) 
data
[[0, 0, 0]]
# 读取数据
data = []
with open('../data/data_write_to_file1.txt','r') as f:
    for line in f:
        line = line.replace('\n', '').split('\t')
        line = [int(i) for i in line]
        data.append(line)
data
[[0, 0, 0],
 [1, 1, 1],
 [2, 4, 8],
 [3, 9, 27],
 [4, 16, 64],
 [5, 25, 125],
 [6, 36, 216],
 [7, 49, 343],
 [8, 64, 512],
 [9, 81, 729],
 [10, 100, 1000],
 [11, 121, 1331],
 [12, 144, 1728],
 [13, 169, 2197],
 [14, 196, 2744],
 [15, 225, 3375],
 [16, 256, 4096],
 [17, 289, 4913],
 [18, 324, 5832],
 [19, 361, 6859],
 [20, 400, 8000],
 [21, 441, 9261],
 [22, 484, 10648],
 [23, 529, 12167],
 [24, 576, 13824],
 [25, 625, 15625],
 [26, 676, 17576],
 [27, 729, 19683],
 [28, 784, 21952],
 [29, 841, 24389],
 [30, 900, 27000],
 [31, 961, 29791],
 [32, 1024, 32768],
 [33, 1089, 35937],
 [34, 1156, 39304],
 [35, 1225, 42875],
 [36, 1296, 46656],
 [37, 1369, 50653],
 [38, 1444, 54872],
 [39, 1521, 59319],
 [40, 1600, 64000],
 [41, 1681, 68921],
 [42, 1764, 74088],
 [43, 1849, 79507],
 [44, 1936, 85184],
 [45, 2025, 91125],
 [46, 2116, 97336],
 [47, 2209, 103823],
 [48, 2304, 110592],
 [49, 2401, 117649],
 [50, 2500, 125000],
 [51, 2601, 132651],
 [52, 2704, 140608],
 [53, 2809, 148877],
 [54, 2916, 157464],
 [55, 3025, 166375],
 [56, 3136, 175616],
 [57, 3249, 185193],
 [58, 3364, 195112],
 [59, 3481, 205379],
 [60, 3600, 216000],
 [61, 3721, 226981],
 [62, 3844, 238328],
 [63, 3969, 250047],
 [64, 4096, 262144],
 [65, 4225, 274625],
 [66, 4356, 287496],
 [67, 4489, 300763],
 [68, 4624, 314432],
 [69, 4761, 328509],
 [70, 4900, 343000],
 [71, 5041, 357911],
 [72, 5184, 373248],
 [73, 5329, 389017],
 [74, 5476, 405224],
 [75, 5625, 421875],
 [76, 5776, 438976],
 [77, 5929, 456533],
 [78, 6084, 474552],
 [79, 6241, 493039],
 [80, 6400, 512000],
 [81, 6561, 531441],
 [82, 6724, 551368],
 [83, 6889, 571787],
 [84, 7056, 592704],
 [85, 7225, 614125],
 [86, 7396, 636056],
 [87, 7569, 658503],
 [88, 7744, 681472],
 [89, 7921, 704969],
 [90, 8100, 729000],
 [91, 8281, 753571],
 [92, 8464, 778688],
 [93, 8649, 804357],
 [94, 8836, 830584],
 [95, 9025, 857375],
 [96, 9216, 884736],
 [97, 9409, 912673],
 [98, 9604, 941192],
 [99, 9801, 970299],
 [100, 10000, 1000000],
 [101, 10201, 1030301],
 [102, 10404, 1061208],
 [103, 10609, 1092727],
 [104, 10816, 1124864],
 [105, 11025, 1157625],
 [106, 11236, 1191016],
 [107, 11449, 1225043],
 [108, 11664, 1259712],
 [109, 11881, 1295029],
 [110, 12100, 1331000],
 [111, 12321, 1367631],
 [112, 12544, 1404928],
 [113, 12769, 1442897],
 [114, 12996, 1481544],
 [115, 13225, 1520875],
 [116, 13456, 1560896],
 [117, 13689, 1601613],
 [118, 13924, 1643032],
 [119, 14161, 1685159],
 [120, 14400, 1728000],
 [121, 14641, 1771561],
 [122, 14884, 1815848],
 [123, 15129, 1860867],
 [124, 15376, 1906624],
 [125, 15625, 1953125],
 [126, 15876, 2000376],
 [127, 16129, 2048383],
 [128, 16384, 2097152],
 [129, 16641, 2146689],
 [130, 16900, 2197000],
 [131, 17161, 2248091],
 [132, 17424, 2299968],
 [133, 17689, 2352637],
 [134, 17956, 2406104],
 [135, 18225, 2460375],
 [136, 18496, 2515456],
 [137, 18769, 2571353],
 [138, 19044, 2628072],
 [139, 19321, 2685619],
 [140, 19600, 2744000],
 [141, 19881, 2803221],
 [142, 20164, 2863288],
 [143, 20449, 2924207],
 [144, 20736, 2985984],
 [145, 21025, 3048625],
 [146, 21316, 3112136],
 [147, 21609, 3176523],
 [148, 21904, 3241792],
 [149, 22201, 3307949],
 [150, 22500, 3375000],
 [151, 22801, 3442951],
 [152, 23104, 3511808],
 [153, 23409, 3581577],
 [154, 23716, 3652264],
 [155, 24025, 3723875],
 [156, 24336, 3796416],
 [157, 24649, 3869893],
 [158, 24964, 3944312],
 [159, 25281, 4019679],
 [160, 25600, 4096000],
 [161, 25921, 4173281],
 [162, 26244, 4251528],
 [163, 26569, 4330747],
 [164, 26896, 4410944],
 [165, 27225, 4492125],
 [166, 27556, 4574296],
 [167, 27889, 4657463],
 [168, 28224, 4741632],
 [169, 28561, 4826809],
 [170, 28900, 4913000],
 [171, 29241, 5000211],
 [172, 29584, 5088448],
 [173, 29929, 5177717],
 [174, 30276, 5268024],
 [175, 30625, 5359375],
 [176, 30976, 5451776],
 [177, 31329, 5545233],
 [178, 31684, 5639752],
 [179, 32041, 5735339],
 [180, 32400, 5832000],
 [181, 32761, 5929741],
 [182, 33124, 6028568],
 [183, 33489, 6128487],
 [184, 33856, 6229504],
 [185, 34225, 6331625],
 [186, 34596, 6434856],
 [187, 34969, 6539203],
 [188, 35344, 6644672],
 [189, 35721, 6751269],
 [190, 36100, 6859000],
 [191, 36481, 6967871],
 [192, 36864, 7077888],
 [193, 37249, 7189057],
 [194, 37636, 7301384],
 [195, 38025, 7414875],
 [196, 38416, 7529536],
 [197, 38809, 7645373],
 [198, 39204, 7762392],
 [199, 39601, 7880599],
 [200, 40000, 8000000],
 [201, 40401, 8120601],
 [202, 40804, 8242408],
 [203, 41209, 8365427],
 [204, 41616, 8489664],
 [205, 42025, 8615125],
 [206, 42436, 8741816],
 [207, 42849, 8869743],
 [208, 43264, 8998912],
 [209, 43681, 9129329],
 [210, 44100, 9261000],
 [211, 44521, 9393931],
 [212, 44944, 9528128],
 [213, 45369, 9663597],
 [214, 45796, 9800344],
 [215, 46225, 9938375],
 [216, 46656, 10077696],
 [217, 47089, 10218313],
 [218, 47524, 10360232],
 [219, 47961, 10503459],
 [220, 48400, 10648000],
 [221, 48841, 10793861],
 [222, 49284, 10941048],
 [223, 49729, 11089567],
 [224, 50176, 11239424],
 [225, 50625, 11390625],
 [226, 51076, 11543176],
 [227, 51529, 11697083],
 [228, 51984, 11852352],
 [229, 52441, 12008989],
 [230, 52900, 12167000],
 [231, 53361, 12326391],
 [232, 53824, 12487168],
 [233, 54289, 12649337],
 [234, 54756, 12812904],
 [235, 55225, 12977875],
 [236, 55696, 13144256],
 [237, 56169, 13312053],
 [238, 56644, 13481272],
 [239, 57121, 13651919],
 [240, 57600, 13824000],
 [241, 58081, 13997521],
 [242, 58564, 14172488],
 [243, 59049, 14348907],
 [244, 59536, 14526784],
 [245, 60025, 14706125],
 [246, 60516, 14886936],
 [247, 61009, 15069223],
 [248, 61504, 15252992],
 [249, 62001, 15438249],
 [250, 62500, 15625000],
 [251, 63001, 15813251],
 [252, 63504, 16003008],
 [253, 64009, 16194277],
 [254, 64516, 16387064],
 [255, 65025, 16581375],
 [256, 65536, 16777216],
 [257, 66049, 16974593],
 [258, 66564, 17173512],
 [259, 67081, 17373979],
 [260, 67600, 17576000],
 [261, 68121, 17779581],
 [262, 68644, 17984728],
 [263, 69169, 18191447],
 [264, 69696, 18399744],
 [265, 70225, 18609625],
 [266, 70756, 18821096],
 [267, 71289, 19034163],
 [268, 71824, 19248832],
 [269, 72361, 19465109],
 [270, 72900, 19683000],
 [271, 73441, 19902511],
 [272, 73984, 20123648],
 [273, 74529, 20346417],
 [274, 75076, 20570824],
 [275, 75625, 20796875],
 [276, 76176, 21024576],
 [277, 76729, 21253933],
 [278, 77284, 21484952],
 [279, 77841, 21717639],
 [280, 78400, 21952000],
 [281, 78961, 22188041],
 [282, 79524, 22425768],
 [283, 80089, 22665187],
 [284, 80656, 22906304],
 [285, 81225, 23149125],
 [286, 81796, 23393656],
 [287, 82369, 23639903],
 [288, 82944, 23887872],
 [289, 83521, 24137569],
 [290, 84100, 24389000],
 [291, 84681, 24642171],
 [292, 85264, 24897088],
 [293, 85849, 25153757],
 [294, 86436, 25412184],
 [295, 87025, 25672375],
 [296, 87616, 25934336],
 [297, 88209, 26198073],
 [298, 88804, 26463592],
 [299, 89401, 26730899],
 [300, 90000, 27000000],
 [301, 90601, 27270901],
 [302, 91204, 27543608],
 [303, 91809, 27818127],
 [304, 92416, 28094464],
 [305, 93025, 28372625],
 [306, 93636, 28652616],
 [307, 94249, 28934443],
 [308, 94864, 29218112],
 [309, 95481, 29503629],
 [310, 96100, 29791000],
 [311, 96721, 30080231],
 [312, 97344, 30371328],
 [313, 97969, 30664297],
 [314, 98596, 30959144],
 [315, 99225, 31255875],
 [316, 99856, 31554496],
 [317, 100489, 31855013],
 [318, 101124, 32157432],
 [319, 101761, 32461759],
 [320, 102400, 32768000],
 [321, 103041, 33076161],
 [322, 103684, 33386248],
 [323, 104329, 33698267],
 [324, 104976, 34012224],
 [325, 105625, 34328125],
 [326, 106276, 34645976],
 [327, 106929, 34965783],
 [328, 107584, 35287552],
 [329, 108241, 35611289],
 [330, 108900, 35937000],
 [331, 109561, 36264691],
 [332, 110224, 36594368],
 [333, 110889, 36926037],
 [334, 111556, 37259704],
 [335, 112225, 37595375],
 [336, 112896, 37933056],
 [337, 113569, 38272753],
 [338, 114244, 38614472],
 [339, 114921, 38958219],
 [340, 115600, 39304000],
 [341, 116281, 39651821],
 [342, 116964, 40001688],
 [343, 117649, 40353607],
 [344, 118336, 40707584],
 [345, 119025, 41063625],
 [346, 119716, 41421736],
 [347, 120409, 41781923],
 [348, 121104, 42144192],
 [349, 121801, 42508549],
 [350, 122500, 42875000],
 [351, 123201, 43243551],
 [352, 123904, 43614208],
 [353, 124609, 43986977],
 [354, 125316, 44361864],
 [355, 126025, 44738875],
 [356, 126736, 45118016],
 [357, 127449, 45499293],
 [358, 128164, 45882712],
 [359, 128881, 46268279],
 [360, 129600, 46656000],
 [361, 130321, 47045881],
 [362, 131044, 47437928],
 [363, 131769, 47832147],
 [364, 132496, 48228544],
 [365, 133225, 48627125],
 [366, 133956, 49027896],
 [367, 134689, 49430863],
 [368, 135424, 49836032],
 [369, 136161, 50243409],
 [370, 136900, 50653000],
 [371, 137641, 51064811],
 [372, 138384, 51478848],
 [373, 139129, 51895117],
 [374, 139876, 52313624],
 [375, 140625, 52734375],
 [376, 141376, 53157376],
 [377, 142129, 53582633],
 [378, 142884, 54010152],
 [379, 143641, 54439939],
 [380, 144400, 54872000],
 [381, 145161, 55306341],
 [382, 145924, 55742968],
 [383, 146689, 56181887],
 [384, 147456, 56623104],
 [385, 148225, 57066625],
 [386, 148996, 57512456],
 [387, 149769, 57960603],
 [388, 150544, 58411072],
 [389, 151321, 58863869],
 [390, 152100, 59319000],
 [391, 152881, 59776471],
 [392, 153664, 60236288],
 [393, 154449, 60698457],
 [394, 155236, 61162984],
 [395, 156025, 61629875],
 [396, 156816, 62099136],
 [397, 157609, 62570773],
 [398, 158404, 63044792],
 [399, 159201, 63521199],
 [400, 160000, 64000000],
 [401, 160801, 64481201],
 [402, 161604, 64964808],
 [403, 162409, 65450827],
 [404, 163216, 65939264],
 [405, 164025, 66430125],
 [406, 164836, 66923416],
 [407, 165649, 67419143],
 [408, 166464, 67917312],
 [409, 167281, 68417929],
 [410, 168100, 68921000],
 [411, 168921, 69426531],
 [412, 169744, 69934528],
 [413, 170569, 70444997],
 [414, 171396, 70957944],
 [415, 172225, 71473375],
 [416, 173056, 71991296],
 [417, 173889, 72511713],
 [418, 174724, 73034632],
 [419, 175561, 73560059],
 [420, 176400, 74088000],
 [421, 177241, 74618461],
 [422, 178084, 75151448],
 [423, 178929, 75686967],
 [424, 179776, 76225024],
 [425, 180625, 76765625],
 [426, 181476, 77308776],
 [427, 182329, 77854483],
 [428, 183184, 78402752],
 [429, 184041, 78953589],
 [430, 184900, 79507000],
 [431, 185761, 80062991],
 [432, 186624, 80621568],
 [433, 187489, 81182737],
 [434, 188356, 81746504],
 [435, 189225, 82312875],
 [436, 190096, 82881856],
 [437, 190969, 83453453],
 [438, 191844, 84027672],
 [439, 192721, 84604519],
 [440, 193600, 85184000],
 [441, 194481, 85766121],
 [442, 195364, 86350888],
 [443, 196249, 86938307],
 [444, 197136, 87528384],
 [445, 198025, 88121125],
 [446, 198916, 88716536],
 [447, 199809, 89314623],
 [448, 200704, 89915392],
 [449, 201601, 90518849],
 [450, 202500, 91125000],
 [451, 203401, 91733851],
 [452, 204304, 92345408],
 [453, 205209, 92959677],
 [454, 206116, 93576664],
 [455, 207025, 94196375],
 [456, 207936, 94818816],
 [457, 208849, 95443993],
 [458, 209764, 96071912],
 [459, 210681, 96702579],
 [460, 211600, 97336000],
 [461, 212521, 97972181],
 [462, 213444, 98611128],
 [463, 214369, 99252847],
 [464, 215296, 99897344],
 [465, 216225, 100544625],
 [466, 217156, 101194696],
 [467, 218089, 101847563],
 [468, 219024, 102503232],
 [469, 219961, 103161709],
 [470, 220900, 103823000],
 [471, 221841, 104487111],
 [472, 222784, 105154048],
 [473, 223729, 105823817],
 [474, 224676, 106496424],
 [475, 225625, 107171875],
 [476, 226576, 107850176],
 [477, 227529, 108531333],
 [478, 228484, 109215352],
 [479, 229441, 109902239],
 [480, 230400, 110592000],
 [481, 231361, 111284641],
 [482, 232324, 111980168],
 [483, 233289, 112678587],
 [484, 234256, 113379904],
 [485, 235225, 114084125],
 [486, 236196, 114791256],
 [487, 237169, 115501303],
 [488, 238144, 116214272],
 [489, 239121, 116930169],
 [490, 240100, 117649000],
 [491, 241081, 118370771],
 [492, 242064, 119095488],
 [493, 243049, 119823157],
 [494, 244036, 120553784],
 [495, 245025, 121287375],
 [496, 246016, 122023936],
 [497, 247009, 122763473],
 [498, 248004, 123505992],
 [499, 249001, 124251499],
 [500, 250000, 125000000],
 [501, 251001, 125751501],
 [502, 252004, 126506008],
 [503, 253009, 127263527],
 [504, 254016, 128024064],
 [505, 255025, 128787625],
 [506, 256036, 129554216],
 [507, 257049, 130323843],
 [508, 258064, 131096512],
 [509, 259081, 131872229],
 [510, 260100, 132651000],
 [511, 261121, 133432831],
 [512, 262144, 134217728],
 [513, 263169, 135005697],
 [514, 264196, 135796744],
 [515, 265225, 136590875],
 [516, 266256, 137388096],
 [517, 267289, 138188413],
 [518, 268324, 138991832],
 [519, 269361, 139798359],
 [520, 270400, 140608000],
 [521, 271441, 141420761],
 [522, 272484, 142236648],
 [523, 273529, 143055667],
 [524, 274576, 143877824],
 [525, 275625, 144703125],
 [526, 276676, 145531576],
 [527, 277729, 146363183],
 [528, 278784, 147197952],
 [529, 279841, 148035889],
 [530, 280900, 148877000],
 [531, 281961, 149721291],
 [532, 283024, 150568768],
 [533, 284089, 151419437],
 [534, 285156, 152273304],
 [535, 286225, 153130375],
 [536, 287296, 153990656],
 [537, 288369, 154854153],
 [538, 289444, 155720872],
 [539, 290521, 156590819],
 [540, 291600, 157464000],
 [541, 292681, 158340421],
 [542, 293764, 159220088],
 [543, 294849, 160103007],
 [544, 295936, 160989184],
 [545, 297025, 161878625],
 [546, 298116, 162771336],
 [547, 299209, 163667323],
 [548, 300304, 164566592],
 [549, 301401, 165469149],
 [550, 302500, 166375000],
 [551, 303601, 167284151],
 [552, 304704, 168196608],
 [553, 305809, 169112377],
 [554, 306916, 170031464],
 [555, 308025, 170953875],
 [556, 309136, 171879616],
 [557, 310249, 172808693],
 [558, 311364, 173741112],
 [559, 312481, 174676879],
 [560, 313600, 175616000],
 [561, 314721, 176558481],
 [562, 315844, 177504328],
 [563, 316969, 178453547],
 [564, 318096, 179406144],
 [565, 319225, 180362125],
 [566, 320356, 181321496],
 [567, 321489, 182284263],
 [568, 322624, 183250432],
 [569, 323761, 184220009],
 [570, 324900, 185193000],
 [571, 326041, 186169411],
 [572, 327184, 187149248],
 [573, 328329, 188132517],
 [574, 329476, 189119224],
 [575, 330625, 190109375],
 [576, 331776, 191102976],
 [577, 332929, 192100033],
 [578, 334084, 193100552],
 [579, 335241, 194104539],
 [580, 336400, 195112000],
 [581, 337561, 196122941],
 [582, 338724, 197137368],
 [583, 339889, 198155287],
 [584, 341056, 199176704],
 [585, 342225, 200201625],
 [586, 343396, 201230056],
 [587, 344569, 202262003],
 [588, 345744, 203297472],
 [589, 346921, 204336469],
 [590, 348100, 205379000],
 [591, 349281, 206425071],
 [592, 350464, 207474688],
 [593, 351649, 208527857],
 [594, 352836, 209584584],
 [595, 354025, 210644875],
 [596, 355216, 211708736],
 [597, 356409, 212776173],
 [598, 357604, 213847192],
 [599, 358801, 214921799],
 [600, 360000, 216000000],
 [601, 361201, 217081801],
 [602, 362404, 218167208],
 [603, 363609, 219256227],
 [604, 364816, 220348864],
 [605, 366025, 221445125],
 [606, 367236, 222545016],
 [607, 368449, 223648543],
 [608, 369664, 224755712],
 [609, 370881, 225866529],
 [610, 372100, 226981000],
 [611, 373321, 228099131],
 [612, 374544, 229220928],
 [613, 375769, 230346397],
 [614, 376996, 231475544],
 [615, 378225, 232608375],
 [616, 379456, 233744896],
 [617, 380689, 234885113],
 [618, 381924, 236029032],
 [619, 383161, 237176659],
 [620, 384400, 238328000],
 [621, 385641, 239483061],
 [622, 386884, 240641848],
 [623, 388129, 241804367],
 [624, 389376, 242970624],
 [625, 390625, 244140625],
 [626, 391876, 245314376],
 [627, 393129, 246491883],
 [628, 394384, 247673152],
 [629, 395641, 248858189],
 [630, 396900, 250047000],
 [631, 398161, 251239591],
 [632, 399424, 252435968],
 [633, 400689, 253636137],
 [634, 401956, 254840104],
 [635, 403225, 256047875],
 [636, 404496, 257259456],
 [637, 405769, 258474853],
 [638, 407044, 259694072],
 [639, 408321, 260917119],
 [640, 409600, 262144000],
 [641, 410881, 263374721],
 [642, 412164, 264609288],
 [643, 413449, 265847707],
 [644, 414736, 267089984],
 [645, 416025, 268336125],
 [646, 417316, 269586136],
 [647, 418609, 270840023],
 [648, 419904, 272097792],
 [649, 421201, 273359449],
 [650, 422500, 274625000],
 [651, 423801, 275894451],
 [652, 425104, 277167808],
 [653, 426409, 278445077],
 [654, 427716, 279726264],
 [655, 429025, 281011375],
 [656, 430336, 282300416],
 [657, 431649, 283593393],
 [658, 432964, 284890312],
 [659, 434281, 286191179],
 [660, 435600, 287496000],
 [661, 436921, 288804781],
 [662, 438244, 290117528],
 [663, 439569, 291434247],
 [664, 440896, 292754944],
 [665, 442225, 294079625],
 [666, 443556, 295408296],
 [667, 444889, 296740963],
 [668, 446224, 298077632],
 [669, 447561, 299418309],
 [670, 448900, 300763000],
 [671, 450241, 302111711],
 [672, 451584, 303464448],
 [673, 452929, 304821217],
 [674, 454276, 306182024],
 [675, 455625, 307546875],
 [676, 456976, 308915776],
 [677, 458329, 310288733],
 [678, 459684, 311665752],
 [679, 461041, 313046839],
 [680, 462400, 314432000],
 [681, 463761, 315821241],
 [682, 465124, 317214568],
 [683, 466489, 318611987],
 [684, 467856, 320013504],
 [685, 469225, 321419125],
 [686, 470596, 322828856],
 [687, 471969, 324242703],
 [688, 473344, 325660672],
 [689, 474721, 327082769],
 [690, 476100, 328509000],
 [691, 477481, 329939371],
 [692, 478864, 331373888],
 [693, 480249, 332812557],
 [694, 481636, 334255384],
 [695, 483025, 335702375],
 [696, 484416, 337153536],
 [697, 485809, 338608873],
 [698, 487204, 340068392],
 [699, 488601, 341532099],
 [700, 490000, 343000000],
 [701, 491401, 344472101],
 [702, 492804, 345948408],
 [703, 494209, 347428927],
 [704, 495616, 348913664],
 [705, 497025, 350402625],
 [706, 498436, 351895816],
 [707, 499849, 353393243],
 [708, 501264, 354894912],
 [709, 502681, 356400829],
 [710, 504100, 357911000],
 [711, 505521, 359425431],
 [712, 506944, 360944128],
 [713, 508369, 362467097],
 [714, 509796, 363994344],
 [715, 511225, 365525875],
 [716, 512656, 367061696],
 [717, 514089, 368601813],
 [718, 515524, 370146232],
 [719, 516961, 371694959],
 [720, 518400, 373248000],
 [721, 519841, 374805361],
 [722, 521284, 376367048],
 [723, 522729, 377933067],
 [724, 524176, 379503424],
 [725, 525625, 381078125],
 [726, 527076, 382657176],
 [727, 528529, 384240583],
 [728, 529984, 385828352],
 [729, 531441, 387420489],
 [730, 532900, 389017000],
 [731, 534361, 390617891],
 [732, 535824, 392223168],
 [733, 537289, 393832837],
 [734, 538756, 395446904],
 [735, 540225, 397065375],
 [736, 541696, 398688256],
 [737, 543169, 400315553],
 [738, 544644, 401947272],
 [739, 546121, 403583419],
 [740, 547600, 405224000],
 [741, 549081, 406869021],
 [742, 550564, 408518488],
 [743, 552049, 410172407],
 [744, 553536, 411830784],
 [745, 555025, 413493625],
 [746, 556516, 415160936],
 [747, 558009, 416832723],
 [748, 559504, 418508992],
 [749, 561001, 420189749],
 [750, 562500, 421875000],
 [751, 564001, 423564751],
 [752, 565504, 425259008],
 [753, 567009, 426957777],
 [754, 568516, 428661064],
 [755, 570025, 430368875],
 [756, 571536, 432081216],
 [757, 573049, 433798093],
 [758, 574564, 435519512],
 [759, 576081, 437245479],
 [760, 577600, 438976000],
 [761, 579121, 440711081],
 [762, 580644, 442450728],
 [763, 582169, 444194947],
 [764, 583696, 445943744],
 [765, 585225, 447697125],
 [766, 586756, 449455096],
 [767, 588289, 451217663],
 [768, 589824, 452984832],
 [769, 591361, 454756609],
 [770, 592900, 456533000],
 [771, 594441, 458314011],
 [772, 595984, 460099648],
 [773, 597529, 461889917],
 [774, 599076, 463684824],
 [775, 600625, 465484375],
 [776, 602176, 467288576],
 [777, 603729, 469097433],
 [778, 605284, 470910952],
 [779, 606841, 472729139],
 [780, 608400, 474552000],
 [781, 609961, 476379541],
 [782, 611524, 478211768],
 [783, 613089, 480048687],
 [784, 614656, 481890304],
 [785, 616225, 483736625],
 [786, 617796, 485587656],
 [787, 619369, 487443403],
 [788, 620944, 489303872],
 [789, 622521, 491169069],
 [790, 624100, 493039000],
 [791, 625681, 494913671],
 [792, 627264, 496793088],
 [793, 628849, 498677257],
 [794, 630436, 500566184],
 [795, 632025, 502459875],
 [796, 633616, 504358336],
 [797, 635209, 506261573],
 [798, 636804, 508169592],
 [799, 638401, 510082399],
 [800, 640000, 512000000],
 [801, 641601, 513922401],
 [802, 643204, 515849608],
 [803, 644809, 517781627],
 [804, 646416, 519718464],
 [805, 648025, 521660125],
 [806, 649636, 523606616],
 [807, 651249, 525557943],
 [808, 652864, 527514112],
 [809, 654481, 529475129],
 [810, 656100, 531441000],
 [811, 657721, 533411731],
 [812, 659344, 535387328],
 [813, 660969, 537367797],
 [814, 662596, 539353144],
 [815, 664225, 541343375],
 [816, 665856, 543338496],
 [817, 667489, 545338513],
 [818, 669124, 547343432],
 [819, 670761, 549353259],
 [820, 672400, 551368000],
 [821, 674041, 553387661],
 [822, 675684, 555412248],
 [823, 677329, 557441767],
 [824, 678976, 559476224],
 [825, 680625, 561515625],
 [826, 682276, 563559976],
 [827, 683929, 565609283],
 [828, 685584, 567663552],
 [829, 687241, 569722789],
 [830, 688900, 571787000],
 [831, 690561, 573856191],
 [832, 692224, 575930368],
 [833, 693889, 578009537],
 [834, 695556, 580093704],
 [835, 697225, 582182875],
 [836, 698896, 584277056],
 [837, 700569, 586376253],
 [838, 702244, 588480472],
 [839, 703921, 590589719],
 [840, 705600, 592704000],
 [841, 707281, 594823321],
 [842, 708964, 596947688],
 [843, 710649, 599077107],
 [844, 712336, 601211584],
 [845, 714025, 603351125],
 [846, 715716, 605495736],
 [847, 717409, 607645423],
 [848, 719104, 609800192],
 [849, 720801, 611960049],
 [850, 722500, 614125000],
 [851, 724201, 616295051],
 [852, 725904, 618470208],
 [853, 727609, 620650477],
 [854, 729316, 622835864],
 [855, 731025, 625026375],
 [856, 732736, 627222016],
 [857, 734449, 629422793],
 [858, 736164, 631628712],
 [859, 737881, 633839779],
 [860, 739600, 636056000],
 [861, 741321, 638277381],
 [862, 743044, 640503928],
 [863, 744769, 642735647],
 [864, 746496, 644972544],
 [865, 748225, 647214625],
 [866, 749956, 649461896],
 [867, 751689, 651714363],
 [868, 753424, 653972032],
 [869, 755161, 656234909],
 [870, 756900, 658503000],
 [871, 758641, 660776311],
 [872, 760384, 663054848],
 [873, 762129, 665338617],
 [874, 763876, 667627624],
 [875, 765625, 669921875],
 [876, 767376, 672221376],
 [877, 769129, 674526133],
 [878, 770884, 676836152],
 [879, 772641, 679151439],
 [880, 774400, 681472000],
 [881, 776161, 683797841],
 [882, 777924, 686128968],
 [883, 779689, 688465387],
 [884, 781456, 690807104],
 [885, 783225, 693154125],
 [886, 784996, 695506456],
 [887, 786769, 697864103],
 [888, 788544, 700227072],
 [889, 790321, 702595369],
 [890, 792100, 704969000],
 [891, 793881, 707347971],
 [892, 795664, 709732288],
 [893, 797449, 712121957],
 [894, 799236, 714516984],
 [895, 801025, 716917375],
 [896, 802816, 719323136],
 [897, 804609, 721734273],
 [898, 806404, 724150792],
 [899, 808201, 726572699],
 [900, 810000, 729000000],
 [901, 811801, 731432701],
 [902, 813604, 733870808],
 [903, 815409, 736314327],
 [904, 817216, 738763264],
 [905, 819025, 741217625],
 [906, 820836, 743677416],
 [907, 822649, 746142643],
 [908, 824464, 748613312],
 [909, 826281, 751089429],
 [910, 828100, 753571000],
 [911, 829921, 756058031],
 [912, 831744, 758550528],
 [913, 833569, 761048497],
 [914, 835396, 763551944],
 [915, 837225, 766060875],
 [916, 839056, 768575296],
 [917, 840889, 771095213],
 [918, 842724, 773620632],
 [919, 844561, 776151559],
 [920, 846400, 778688000],
 [921, 848241, 781229961],
 [922, 850084, 783777448],
 [923, 851929, 786330467],
 [924, 853776, 788889024],
 [925, 855625, 791453125],
 [926, 857476, 794022776],
 [927, 859329, 796597983],
 [928, 861184, 799178752],
 [929, 863041, 801765089],
 [930, 864900, 804357000],
 [931, 866761, 806954491],
 [932, 868624, 809557568],
 [933, 870489, 812166237],
 [934, 872356, 814780504],
 [935, 874225, 817400375],
 [936, 876096, 820025856],
 [937, 877969, 822656953],
 [938, 879844, 825293672],
 [939, 881721, 827936019],
 [940, 883600, 830584000],
 [941, 885481, 833237621],
 [942, 887364, 835896888],
 [943, 889249, 838561807],
 [944, 891136, 841232384],
 [945, 893025, 843908625],
 [946, 894916, 846590536],
 [947, 896809, 849278123],
 [948, 898704, 851971392],
 [949, 900601, 854670349],
 [950, 902500, 857375000],
 [951, 904401, 860085351],
 [952, 906304, 862801408],
 [953, 908209, 865523177],
 [954, 910116, 868250664],
 [955, 912025, 870983875],
 [956, 913936, 873722816],
 [957, 915849, 876467493],
 [958, 917764, 879217912],
 [959, 919681, 881974079],
 [960, 921600, 884736000],
 [961, 923521, 887503681],
 [962, 925444, 890277128],
 [963, 927369, 893056347],
 [964, 929296, 895841344],
 [965, 931225, 898632125],
 [966, 933156, 901428696],
 [967, 935089, 904231063],
 [968, 937024, 907039232],
 [969, 938961, 909853209],
 [970, 940900, 912673000],
 [971, 942841, 915498611],
 [972, 944784, 918330048],
 [973, 946729, 921167317],
 [974, 948676, 924010424],
 [975, 950625, 926859375],
 [976, 952576, 929714176],
 [977, 954529, 932574833],
 [978, 956484, 935441352],
 [979, 958441, 938313739],
 [980, 960400, 941192000],
 [981, 962361, 944076141],
 [982, 964324, 946966168],
 [983, 966289, 949862087],
 [984, 968256, 952763904],
 [985, 970225, 955671625],
 [986, 972196, 958585256],
 [987, 974169, 961504803],
 [988, 976144, 964430272],
 [989, 978121, 967361669],
 [990, 980100, 970299000],
 [991, 982081, 973242271],
 [992, 984064, 976191488],
 [993, 986049, 979146657],
 [994, 988036, 982107784],
 [995, 990025, 985074875],
 [996, 992016, 988047936],
 [997, 994009, 991026973],
 [998, 996004, 994011992],
 [999, 998001, 997002999],
 ...]
# 读取数据
data = []
with open('../data/data_write_to_file.txt','r') as f:
    for line in f:
        line = line.replace('\n', '').split('\t')
        line = [int(i) for i in line]
        data.append(line)
data
[[0, 0, 0],
 [1, 1, 1],
 [2, 4, 8],
 [3, 9, 27],
 [4, 16, 64],
 [5, 25, 125],
 [6, 36, 216],
 [7, 49, 343],
 [8, 64, 512],
 [9, 81, 729],
 [10, 100, 1000],
 [11, 121, 1331],
 [12, 144, 1728],
 [13, 169, 2197],
 [14, 196, 2744],
 [15, 225, 3375],
 [16, 256, 4096],
 [17, 289, 4913],
 [18, 324, 5832],
 [19, 361, 6859],
 [20, 400, 8000],
 [21, 441, 9261],
 [22, 484, 10648],
 [23, 529, 12167],
 [24, 576, 13824],
 [25, 625, 15625],
 [26, 676, 17576],
 [27, 729, 19683],
 [28, 784, 21952],
 [29, 841, 24389],
 [30, 900, 27000],
 [31, 961, 29791],
 [32, 1024, 32768],
 [33, 1089, 35937],
 [34, 1156, 39304],
 [35, 1225, 42875],
 [36, 1296, 46656],
 [37, 1369, 50653],
 [38, 1444, 54872],
 [39, 1521, 59319],
 [40, 1600, 64000],
 [41, 1681, 68921],
 [42, 1764, 74088],
 [43, 1849, 79507],
 [44, 1936, 85184],
 [45, 2025, 91125],
 [46, 2116, 97336],
 [47, 2209, 103823],
 [48, 2304, 110592],
 [49, 2401, 117649],
 [50, 2500, 125000],
 [51, 2601, 132651],
 [52, 2704, 140608],
 [53, 2809, 148877],
 [54, 2916, 157464],
 [55, 3025, 166375],
 [56, 3136, 175616],
 [57, 3249, 185193],
 [58, 3364, 195112],
 [59, 3481, 205379],
 [60, 3600, 216000],
 [61, 3721, 226981],
 [62, 3844, 238328],
 [63, 3969, 250047],
 [64, 4096, 262144],
 [65, 4225, 274625],
 [66, 4356, 287496],
 [67, 4489, 300763],
 [68, 4624, 314432],
 [69, 4761, 328509],
 [70, 4900, 343000],
 [71, 5041, 357911],
 [72, 5184, 373248],
 [73, 5329, 389017],
 [74, 5476, 405224],
 [75, 5625, 421875],
 [76, 5776, 438976],
 [77, 5929, 456533],
 [78, 6084, 474552],
 [79, 6241, 493039],
 [80, 6400, 512000],
 [81, 6561, 531441],
 [82, 6724, 551368],
 [83, 6889, 571787],
 [84, 7056, 592704],
 [85, 7225, 614125],
 [86, 7396, 636056],
 [87, 7569, 658503],
 [88, 7744, 681472],
 [89, 7921, 704969],
 [90, 8100, 729000],
 [91, 8281, 753571],
 [92, 8464, 778688],
 [93, 8649, 804357],
 [94, 8836, 830584],
 [95, 9025, 857375],
 [96, 9216, 884736],
 [97, 9409, 912673],
 [98, 9604, 941192],
 [99, 9801, 970299],
 [100, 10000, 1000000],
 [101, 10201, 1030301],
 [102, 10404, 1061208],
 [103, 10609, 1092727],
 [104, 10816, 1124864],
 [105, 11025, 1157625],
 [106, 11236, 1191016],
 [107, 11449, 1225043],
 [108, 11664, 1259712],
 [109, 11881, 1295029],
 [110, 12100, 1331000],
 [111, 12321, 1367631],
 [112, 12544, 1404928],
 [113, 12769, 1442897],
 [114, 12996, 1481544],
 [115, 13225, 1520875],
 [116, 13456, 1560896],
 [117, 13689, 1601613],
 [118, 13924, 1643032],
 [119, 14161, 1685159],
 [120, 14400, 1728000],
 [121, 14641, 1771561],
 [122, 14884, 1815848],
 [123, 15129, 1860867],
 [124, 15376, 1906624],
 [125, 15625, 1953125],
 [126, 15876, 2000376],
 [127, 16129, 2048383],
 [128, 16384, 2097152],
 [129, 16641, 2146689],
 [130, 16900, 2197000],
 [131, 17161, 2248091],
 [132, 17424, 2299968],
 [133, 17689, 2352637],
 [134, 17956, 2406104],
 [135, 18225, 2460375],
 [136, 18496, 2515456],
 [137, 18769, 2571353],
 [138, 19044, 2628072],
 [139, 19321, 2685619],
 [140, 19600, 2744000],
 [141, 19881, 2803221],
 [142, 20164, 2863288],
 [143, 20449, 2924207],
 [144, 20736, 2985984],
 [145, 21025, 3048625],
 [146, 21316, 3112136],
 [147, 21609, 3176523],
 [148, 21904, 3241792],
 [149, 22201, 3307949],
 [150, 22500, 3375000],
 [151, 22801, 3442951],
 [152, 23104, 3511808],
 [153, 23409, 3581577],
 [154, 23716, 3652264],
 [155, 24025, 3723875],
 [156, 24336, 3796416],
 [157, 24649, 3869893],
 [158, 24964, 3944312],
 [159, 25281, 4019679],
 [160, 25600, 4096000],
 [161, 25921, 4173281],
 [162, 26244, 4251528],
 [163, 26569, 4330747],
 [164, 26896, 4410944],
 [165, 27225, 4492125],
 [166, 27556, 4574296],
 [167, 27889, 4657463],
 [168, 28224, 4741632],
 [169, 28561, 4826809],
 [170, 28900, 4913000],
 [171, 29241, 5000211],
 [172, 29584, 5088448],
 [173, 29929, 5177717],
 [174, 30276, 5268024],
 [175, 30625, 5359375],
 [176, 30976, 5451776],
 [177, 31329, 5545233],
 [178, 31684, 5639752],
 [179, 32041, 5735339],
 [180, 32400, 5832000],
 [181, 32761, 5929741],
 [182, 33124, 6028568],
 [183, 33489, 6128487],
 [184, 33856, 6229504],
 [185, 34225, 6331625],
 [186, 34596, 6434856],
 [187, 34969, 6539203],
 [188, 35344, 6644672],
 [189, 35721, 6751269],
 [190, 36100, 6859000],
 [191, 36481, 6967871],
 [192, 36864, 7077888],
 [193, 37249, 7189057],
 [194, 37636, 7301384],
 [195, 38025, 7414875],
 [196, 38416, 7529536],
 [197, 38809, 7645373],
 [198, 39204, 7762392],
 [199, 39601, 7880599],
 [200, 40000, 8000000],
 [201, 40401, 8120601],
 [202, 40804, 8242408],
 [203, 41209, 8365427],
 [204, 41616, 8489664],
 [205, 42025, 8615125],
 [206, 42436, 8741816],
 [207, 42849, 8869743],
 [208, 43264, 8998912],
 [209, 43681, 9129329],
 [210, 44100, 9261000],
 [211, 44521, 9393931],
 [212, 44944, 9528128],
 [213, 45369, 9663597],
 [214, 45796, 9800344],
 [215, 46225, 9938375],
 [216, 46656, 10077696],
 [217, 47089, 10218313],
 [218, 47524, 10360232],
 [219, 47961, 10503459],
 [220, 48400, 10648000],
 [221, 48841, 10793861],
 [222, 49284, 10941048],
 [223, 49729, 11089567],
 [224, 50176, 11239424],
 [225, 50625, 11390625],
 [226, 51076, 11543176],
 [227, 51529, 11697083],
 [228, 51984, 11852352],
 [229, 52441, 12008989],
 [230, 52900, 12167000],
 [231, 53361, 12326391],
 [232, 53824, 12487168],
 [233, 54289, 12649337],
 [234, 54756, 12812904],
 [235, 55225, 12977875],
 [236, 55696, 13144256],
 [237, 56169, 13312053],
 [238, 56644, 13481272],
 [239, 57121, 13651919],
 [240, 57600, 13824000],
 [241, 58081, 13997521],
 [242, 58564, 14172488],
 [243, 59049, 14348907],
 [244, 59536, 14526784],
 [245, 60025, 14706125],
 [246, 60516, 14886936],
 [247, 61009, 15069223],
 [248, 61504, 15252992],
 [249, 62001, 15438249],
 [250, 62500, 15625000],
 [251, 63001, 15813251],
 [252, 63504, 16003008],
 [253, 64009, 16194277],
 [254, 64516, 16387064],
 [255, 65025, 16581375],
 [256, 65536, 16777216],
 [257, 66049, 16974593],
 [258, 66564, 17173512],
 [259, 67081, 17373979],
 [260, 67600, 17576000],
 [261, 68121, 17779581],
 [262, 68644, 17984728],
 [263, 69169, 18191447],
 [264, 69696, 18399744],
 [265, 70225, 18609625],
 [266, 70756, 18821096],
 [267, 71289, 19034163],
 [268, 71824, 19248832],
 [269, 72361, 19465109],
 [270, 72900, 19683000],
 [271, 73441, 19902511],
 [272, 73984, 20123648],
 [273, 74529, 20346417],
 [274, 75076, 20570824],
 [275, 75625, 20796875],
 [276, 76176, 21024576],
 [277, 76729, 21253933],
 [278, 77284, 21484952],
 [279, 77841, 21717639],
 [280, 78400, 21952000],
 [281, 78961, 22188041],
 [282, 79524, 22425768],
 [283, 80089, 22665187],
 [284, 80656, 22906304],
 [285, 81225, 23149125],
 [286, 81796, 23393656],
 [287, 82369, 23639903],
 [288, 82944, 23887872],
 [289, 83521, 24137569],
 [290, 84100, 24389000],
 [291, 84681, 24642171],
 [292, 85264, 24897088],
 [293, 85849, 25153757],
 [294, 86436, 25412184],
 [295, 87025, 25672375],
 [296, 87616, 25934336],
 [297, 88209, 26198073],
 [298, 88804, 26463592],
 [299, 89401, 26730899],
 [300, 90000, 27000000],
 [301, 90601, 27270901],
 [302, 91204, 27543608],
 [303, 91809, 27818127],
 [304, 92416, 28094464],
 [305, 93025, 28372625],
 [306, 93636, 28652616],
 [307, 94249, 28934443],
 [308, 94864, 29218112],
 [309, 95481, 29503629],
 [310, 96100, 29791000],
 [311, 96721, 30080231],
 [312, 97344, 30371328],
 [313, 97969, 30664297],
 [314, 98596, 30959144],
 [315, 99225, 31255875],
 [316, 99856, 31554496],
 [317, 100489, 31855013],
 [318, 101124, 32157432],
 [319, 101761, 32461759],
 [320, 102400, 32768000],
 [321, 103041, 33076161],
 [322, 103684, 33386248],
 [323, 104329, 33698267],
 [324, 104976, 34012224],
 [325, 105625, 34328125],
 [326, 106276, 34645976],
 [327, 106929, 34965783],
 [328, 107584, 35287552],
 [329, 108241, 35611289],
 [330, 108900, 35937000],
 [331, 109561, 36264691],
 [332, 110224, 36594368],
 [333, 110889, 36926037],
 [334, 111556, 37259704],
 [335, 112225, 37595375],
 [336, 112896, 37933056],
 [337, 113569, 38272753],
 [338, 114244, 38614472],
 [339, 114921, 38958219],
 [340, 115600, 39304000],
 [341, 116281, 39651821],
 [342, 116964, 40001688],
 [343, 117649, 40353607],
 [344, 118336, 40707584],
 [345, 119025, 41063625],
 [346, 119716, 41421736],
 [347, 120409, 41781923],
 [348, 121104, 42144192],
 [349, 121801, 42508549],
 [350, 122500, 42875000],
 [351, 123201, 43243551],
 [352, 123904, 43614208],
 [353, 124609, 43986977],
 [354, 125316, 44361864],
 [355, 126025, 44738875],
 [356, 126736, 45118016],
 [357, 127449, 45499293],
 [358, 128164, 45882712],
 [359, 128881, 46268279],
 [360, 129600, 46656000],
 [361, 130321, 47045881],
 [362, 131044, 47437928],
 [363, 131769, 47832147],
 [364, 132496, 48228544],
 [365, 133225, 48627125],
 [366, 133956, 49027896],
 [367, 134689, 49430863],
 [368, 135424, 49836032],
 [369, 136161, 50243409],
 [370, 136900, 50653000],
 [371, 137641, 51064811],
 [372, 138384, 51478848],
 [373, 139129, 51895117],
 [374, 139876, 52313624],
 [375, 140625, 52734375],
 [376, 141376, 53157376],
 [377, 142129, 53582633],
 [378, 142884, 54010152],
 [379, 143641, 54439939],
 [380, 144400, 54872000],
 [381, 145161, 55306341],
 [382, 145924, 55742968],
 [383, 146689, 56181887],
 [384, 147456, 56623104],
 [385, 148225, 57066625],
 [386, 148996, 57512456],
 [387, 149769, 57960603],
 [388, 150544, 58411072],
 [389, 151321, 58863869],
 [390, 152100, 59319000],
 [391, 152881, 59776471],
 [392, 153664, 60236288],
 [393, 154449, 60698457],
 [394, 155236, 61162984],
 [395, 156025, 61629875],
 [396, 156816, 62099136],
 [397, 157609, 62570773],
 [398, 158404, 63044792],
 [399, 159201, 63521199],
 [400, 160000, 64000000],
 [401, 160801, 64481201],
 [402, 161604, 64964808],
 [403, 162409, 65450827],
 [404, 163216, 65939264],
 [405, 164025, 66430125],
 [406, 164836, 66923416],
 [407, 165649, 67419143],
 [408, 166464, 67917312],
 [409, 167281, 68417929],
 [410, 168100, 68921000],
 [411, 168921, 69426531],
 [412, 169744, 69934528],
 [413, 170569, 70444997],
 [414, 171396, 70957944],
 [415, 172225, 71473375],
 [416, 173056, 71991296],
 [417, 173889, 72511713],
 [418, 174724, 73034632],
 [419, 175561, 73560059],
 [420, 176400, 74088000],
 [421, 177241, 74618461],
 [422, 178084, 75151448],
 [423, 178929, 75686967],
 [424, 179776, 76225024],
 [425, 180625, 76765625],
 [426, 181476, 77308776],
 [427, 182329, 77854483],
 [428, 183184, 78402752],
 [429, 184041, 78953589],
 [430, 184900, 79507000],
 [431, 185761, 80062991],
 [432, 186624, 80621568],
 [433, 187489, 81182737],
 [434, 188356, 81746504],
 [435, 189225, 82312875],
 [436, 190096, 82881856],
 [437, 190969, 83453453],
 [438, 191844, 84027672],
 [439, 192721, 84604519],
 [440, 193600, 85184000],
 [441, 194481, 85766121],
 [442, 195364, 86350888],
 [443, 196249, 86938307],
 [444, 197136, 87528384],
 [445, 198025, 88121125],
 [446, 198916, 88716536],
 [447, 199809, 89314623],
 [448, 200704, 89915392],
 [449, 201601, 90518849],
 [450, 202500, 91125000],
 [451, 203401, 91733851],
 [452, 204304, 92345408],
 [453, 205209, 92959677],
 [454, 206116, 93576664],
 [455, 207025, 94196375],
 [456, 207936, 94818816],
 [457, 208849, 95443993],
 [458, 209764, 96071912],
 [459, 210681, 96702579],
 [460, 211600, 97336000],
 [461, 212521, 97972181],
 [462, 213444, 98611128],
 [463, 214369, 99252847],
 [464, 215296, 99897344],
 [465, 216225, 100544625],
 [466, 217156, 101194696],
 [467, 218089, 101847563],
 [468, 219024, 102503232],
 [469, 219961, 103161709],
 [470, 220900, 103823000],
 [471, 221841, 104487111],
 [472, 222784, 105154048],
 [473, 223729, 105823817],
 [474, 224676, 106496424],
 [475, 225625, 107171875],
 [476, 226576, 107850176],
 [477, 227529, 108531333],
 [478, 228484, 109215352],
 [479, 229441, 109902239],
 [480, 230400, 110592000],
 [481, 231361, 111284641],
 [482, 232324, 111980168],
 [483, 233289, 112678587],
 [484, 234256, 113379904],
 [485, 235225, 114084125],
 [486, 236196, 114791256],
 [487, 237169, 115501303],
 [488, 238144, 116214272],
 [489, 239121, 116930169],
 [490, 240100, 117649000],
 [491, 241081, 118370771],
 [492, 242064, 119095488],
 [493, 243049, 119823157],
 [494, 244036, 120553784],
 [495, 245025, 121287375],
 [496, 246016, 122023936],
 [497, 247009, 122763473],
 [498, 248004, 123505992],
 [499, 249001, 124251499],
 [500, 250000, 125000000],
 [501, 251001, 125751501],
 [502, 252004, 126506008],
 [503, 253009, 127263527],
 [504, 254016, 128024064],
 [505, 255025, 128787625],
 [506, 256036, 129554216],
 [507, 257049, 130323843],
 [508, 258064, 131096512],
 [509, 259081, 131872229],
 [510, 260100, 132651000],
 [511, 261121, 133432831],
 [512, 262144, 134217728],
 [513, 263169, 135005697],
 [514, 264196, 135796744],
 [515, 265225, 136590875],
 [516, 266256, 137388096],
 [517, 267289, 138188413],
 [518, 268324, 138991832],
 [519, 269361, 139798359],
 [520, 270400, 140608000],
 [521, 271441, 141420761],
 [522, 272484, 142236648],
 [523, 273529, 143055667],
 [524, 274576, 143877824],
 [525, 275625, 144703125],
 [526, 276676, 145531576],
 [527, 277729, 146363183],
 [528, 278784, 147197952],
 [529, 279841, 148035889],
 [530, 280900, 148877000],
 [531, 281961, 149721291],
 [532, 283024, 150568768],
 [533, 284089, 151419437],
 [534, 285156, 152273304],
 [535, 286225, 153130375],
 [536, 287296, 153990656],
 [537, 288369, 154854153],
 [538, 289444, 155720872],
 [539, 290521, 156590819],
 [540, 291600, 157464000],
 [541, 292681, 158340421],
 [542, 293764, 159220088],
 [543, 294849, 160103007],
 [544, 295936, 160989184],
 [545, 297025, 161878625],
 [546, 298116, 162771336],
 [547, 299209, 163667323],
 [548, 300304, 164566592],
 [549, 301401, 165469149],
 [550, 302500, 166375000],
 [551, 303601, 167284151],
 [552, 304704, 168196608],
 [553, 305809, 169112377],
 [554, 306916, 170031464],
 [555, 308025, 170953875],
 [556, 309136, 171879616],
 [557, 310249, 172808693],
 [558, 311364, 173741112],
 [559, 312481, 174676879],
 [560, 313600, 175616000],
 [561, 314721, 176558481],
 [562, 315844, 177504328],
 [563, 316969, 178453547],
 [564, 318096, 179406144],
 [565, 319225, 180362125],
 [566, 320356, 181321496],
 [567, 321489, 182284263],
 [568, 322624, 183250432],
 [569, 323761, 184220009],
 [570, 324900, 185193000],
 [571, 326041, 186169411],
 [572, 327184, 187149248],
 [573, 328329, 188132517],
 [574, 329476, 189119224],
 [575, 330625, 190109375],
 [576, 331776, 191102976],
 [577, 332929, 192100033],
 [578, 334084, 193100552],
 [579, 335241, 194104539],
 [580, 336400, 195112000],
 [581, 337561, 196122941],
 [582, 338724, 197137368],
 [583, 339889, 198155287],
 [584, 341056, 199176704],
 [585, 342225, 200201625],
 [586, 343396, 201230056],
 [587, 344569, 202262003],
 [588, 345744, 203297472],
 [589, 346921, 204336469],
 [590, 348100, 205379000],
 [591, 349281, 206425071],
 [592, 350464, 207474688],
 [593, 351649, 208527857],
 [594, 352836, 209584584],
 [595, 354025, 210644875],
 [596, 355216, 211708736],
 [597, 356409, 212776173],
 [598, 357604, 213847192],
 [599, 358801, 214921799],
 [600, 360000, 216000000],
 [601, 361201, 217081801],
 [602, 362404, 218167208],
 [603, 363609, 219256227],
 [604, 364816, 220348864],
 [605, 366025, 221445125],
 [606, 367236, 222545016],
 [607, 368449, 223648543],
 [608, 369664, 224755712],
 [609, 370881, 225866529],
 [610, 372100, 226981000],
 [611, 373321, 228099131],
 [612, 374544, 229220928],
 [613, 375769, 230346397],
 [614, 376996, 231475544],
 [615, 378225, 232608375],
 [616, 379456, 233744896],
 [617, 380689, 234885113],
 [618, 381924, 236029032],
 [619, 383161, 237176659],
 [620, 384400, 238328000],
 [621, 385641, 239483061],
 [622, 386884, 240641848],
 [623, 388129, 241804367],
 [624, 389376, 242970624],
 [625, 390625, 244140625],
 [626, 391876, 245314376],
 [627, 393129, 246491883],
 [628, 394384, 247673152],
 [629, 395641, 248858189],
 [630, 396900, 250047000],
 [631, 398161, 251239591],
 [632, 399424, 252435968],
 [633, 400689, 253636137],
 [634, 401956, 254840104],
 [635, 403225, 256047875],
 [636, 404496, 257259456],
 [637, 405769, 258474853],
 [638, 407044, 259694072],
 [639, 408321, 260917119],
 [640, 409600, 262144000],
 [641, 410881, 263374721],
 [642, 412164, 264609288],
 [643, 413449, 265847707],
 [644, 414736, 267089984],
 [645, 416025, 268336125],
 [646, 417316, 269586136],
 [647, 418609, 270840023],
 [648, 419904, 272097792],
 [649, 421201, 273359449],
 [650, 422500, 274625000],
 [651, 423801, 275894451],
 [652, 425104, 277167808],
 [653, 426409, 278445077],
 [654, 427716, 279726264],
 [655, 429025, 281011375],
 [656, 430336, 282300416],
 [657, 431649, 283593393],
 [658, 432964, 284890312],
 [659, 434281, 286191179],
 [660, 435600, 287496000],
 [661, 436921, 288804781],
 [662, 438244, 290117528],
 [663, 439569, 291434247],
 [664, 440896, 292754944],
 [665, 442225, 294079625],
 [666, 443556, 295408296],
 [667, 444889, 296740963],
 [668, 446224, 298077632],
 [669, 447561, 299418309],
 [670, 448900, 300763000],
 [671, 450241, 302111711],
 [672, 451584, 303464448],
 [673, 452929, 304821217],
 [674, 454276, 306182024],
 [675, 455625, 307546875],
 [676, 456976, 308915776],
 [677, 458329, 310288733],
 [678, 459684, 311665752],
 [679, 461041, 313046839],
 [680, 462400, 314432000],
 [681, 463761, 315821241],
 [682, 465124, 317214568],
 [683, 466489, 318611987],
 [684, 467856, 320013504],
 [685, 469225, 321419125],
 [686, 470596, 322828856],
 [687, 471969, 324242703],
 [688, 473344, 325660672],
 [689, 474721, 327082769],
 [690, 476100, 328509000],
 [691, 477481, 329939371],
 [692, 478864, 331373888],
 [693, 480249, 332812557],
 [694, 481636, 334255384],
 [695, 483025, 335702375],
 [696, 484416, 337153536],
 [697, 485809, 338608873],
 [698, 487204, 340068392],
 [699, 488601, 341532099],
 [700, 490000, 343000000],
 [701, 491401, 344472101],
 [702, 492804, 345948408],
 [703, 494209, 347428927],
 [704, 495616, 348913664],
 [705, 497025, 350402625],
 [706, 498436, 351895816],
 [707, 499849, 353393243],
 [708, 501264, 354894912],
 [709, 502681, 356400829],
 [710, 504100, 357911000],
 [711, 505521, 359425431],
 [712, 506944, 360944128],
 [713, 508369, 362467097],
 [714, 509796, 363994344],
 [715, 511225, 365525875],
 [716, 512656, 367061696],
 [717, 514089, 368601813],
 [718, 515524, 370146232],
 [719, 516961, 371694959],
 [720, 518400, 373248000],
 [721, 519841, 374805361],
 [722, 521284, 376367048],
 [723, 522729, 377933067],
 [724, 524176, 379503424],
 [725, 525625, 381078125],
 [726, 527076, 382657176],
 [727, 528529, 384240583],
 [728, 529984, 385828352],
 [729, 531441, 387420489],
 [730, 532900, 389017000],
 [731, 534361, 390617891],
 [732, 535824, 392223168],
 [733, 537289, 393832837],
 [734, 538756, 395446904],
 [735, 540225, 397065375],
 [736, 541696, 398688256],
 [737, 543169, 400315553],
 [738, 544644, 401947272],
 [739, 546121, 403583419],
 [740, 547600, 405224000],
 [741, 549081, 406869021],
 [742, 550564, 408518488],
 [743, 552049, 410172407],
 [744, 553536, 411830784],
 [745, 555025, 413493625],
 [746, 556516, 415160936],
 [747, 558009, 416832723],
 [748, 559504, 418508992],
 [749, 561001, 420189749],
 [750, 562500, 421875000],
 [751, 564001, 423564751],
 [752, 565504, 425259008],
 [753, 567009, 426957777],
 [754, 568516, 428661064],
 [755, 570025, 430368875],
 [756, 571536, 432081216],
 [757, 573049, 433798093],
 [758, 574564, 435519512],
 [759, 576081, 437245479],
 [760, 577600, 438976000],
 [761, 579121, 440711081],
 [762, 580644, 442450728],
 [763, 582169, 444194947],
 [764, 583696, 445943744],
 [765, 585225, 447697125],
 [766, 586756, 449455096],
 [767, 588289, 451217663],
 [768, 589824, 452984832],
 [769, 591361, 454756609],
 [770, 592900, 456533000],
 [771, 594441, 458314011],
 [772, 595984, 460099648],
 [773, 597529, 461889917],
 [774, 599076, 463684824],
 [775, 600625, 465484375],
 [776, 602176, 467288576],
 [777, 603729, 469097433],
 [778, 605284, 470910952],
 [779, 606841, 472729139],
 [780, 608400, 474552000],
 [781, 609961, 476379541],
 [782, 611524, 478211768],
 [783, 613089, 480048687],
 [784, 614656, 481890304],
 [785, 616225, 483736625],
 [786, 617796, 485587656],
 [787, 619369, 487443403],
 [788, 620944, 489303872],
 [789, 622521, 491169069],
 [790, 624100, 493039000],
 [791, 625681, 494913671],
 [792, 627264, 496793088],
 [793, 628849, 498677257],
 [794, 630436, 500566184],
 [795, 632025, 502459875],
 [796, 633616, 504358336],
 [797, 635209, 506261573],
 [798, 636804, 508169592],
 [799, 638401, 510082399],
 [800, 640000, 512000000],
 [801, 641601, 513922401],
 [802, 643204, 515849608],
 [803, 644809, 517781627],
 [804, 646416, 519718464],
 [805, 648025, 521660125],
 [806, 649636, 523606616],
 [807, 651249, 525557943],
 [808, 652864, 527514112],
 [809, 654481, 529475129],
 [810, 656100, 531441000],
 [811, 657721, 533411731],
 [812, 659344, 535387328],
 [813, 660969, 537367797],
 [814, 662596, 539353144],
 [815, 664225, 541343375],
 [816, 665856, 543338496],
 [817, 667489, 545338513],
 [818, 669124, 547343432],
 [819, 670761, 549353259],
 [820, 672400, 551368000],
 [821, 674041, 553387661],
 [822, 675684, 555412248],
 [823, 677329, 557441767],
 [824, 678976, 559476224],
 [825, 680625, 561515625],
 [826, 682276, 563559976],
 [827, 683929, 565609283],
 [828, 685584, 567663552],
 [829, 687241, 569722789],
 [830, 688900, 571787000],
 [831, 690561, 573856191],
 [832, 692224, 575930368],
 [833, 693889, 578009537],
 [834, 695556, 580093704],
 [835, 697225, 582182875],
 [836, 698896, 584277056],
 [837, 700569, 586376253],
 [838, 702244, 588480472],
 [839, 703921, 590589719],
 [840, 705600, 592704000],
 [841, 707281, 594823321],
 [842, 708964, 596947688],
 [843, 710649, 599077107],
 [844, 712336, 601211584],
 [845, 714025, 603351125],
 [846, 715716, 605495736],
 [847, 717409, 607645423],
 [848, 719104, 609800192],
 [849, 720801, 611960049],
 [850, 722500, 614125000],
 [851, 724201, 616295051],
 [852, 725904, 618470208],
 [853, 727609, 620650477],
 [854, 729316, 622835864],
 [855, 731025, 625026375],
 [856, 732736, 627222016],
 [857, 734449, 629422793],
 [858, 736164, 631628712],
 [859, 737881, 633839779],
 [860, 739600, 636056000],
 [861, 741321, 638277381],
 [862, 743044, 640503928],
 [863, 744769, 642735647],
 [864, 746496, 644972544],
 [865, 748225, 647214625],
 [866, 749956, 649461896],
 [867, 751689, 651714363],
 [868, 753424, 653972032],
 [869, 755161, 656234909],
 [870, 756900, 658503000],
 [871, 758641, 660776311],
 [872, 760384, 663054848],
 [873, 762129, 665338617],
 [874, 763876, 667627624],
 [875, 765625, 669921875],
 [876, 767376, 672221376],
 [877, 769129, 674526133],
 [878, 770884, 676836152],
 [879, 772641, 679151439],
 [880, 774400, 681472000],
 [881, 776161, 683797841],
 [882, 777924, 686128968],
 [883, 779689, 688465387],
 [884, 781456, 690807104],
 [885, 783225, 693154125],
 [886, 784996, 695506456],
 [887, 786769, 697864103],
 [888, 788544, 700227072],
 [889, 790321, 702595369],
 [890, 792100, 704969000],
 [891, 793881, 707347971],
 [892, 795664, 709732288],
 [893, 797449, 712121957],
 [894, 799236, 714516984],
 [895, 801025, 716917375],
 [896, 802816, 719323136],
 [897, 804609, 721734273],
 [898, 806404, 724150792],
 [899, 808201, 726572699],
 [900, 810000, 729000000],
 [901, 811801, 731432701],
 [902, 813604, 733870808],
 [903, 815409, 736314327],
 [904, 817216, 738763264],
 [905, 819025, 741217625],
 [906, 820836, 743677416],
 [907, 822649, 746142643],
 [908, 824464, 748613312],
 [909, 826281, 751089429],
 [910, 828100, 753571000],
 [911, 829921, 756058031],
 [912, 831744, 758550528],
 [913, 833569, 761048497],
 [914, 835396, 763551944],
 [915, 837225, 766060875],
 [916, 839056, 768575296],
 [917, 840889, 771095213],
 [918, 842724, 773620632],
 [919, 844561, 776151559],
 [920, 846400, 778688000],
 [921, 848241, 781229961],
 [922, 850084, 783777448],
 [923, 851929, 786330467],
 [924, 853776, 788889024],
 [925, 855625, 791453125],
 [926, 857476, 794022776],
 [927, 859329, 796597983],
 [928, 861184, 799178752],
 [929, 863041, 801765089],
 [930, 864900, 804357000],
 [931, 866761, 806954491],
 [932, 868624, 809557568],
 [933, 870489, 812166237],
 [934, 872356, 814780504],
 [935, 874225, 817400375],
 [936, 876096, 820025856],
 [937, 877969, 822656953],
 [938, 879844, 825293672],
 [939, 881721, 827936019],
 [940, 883600, 830584000],
 [941, 885481, 833237621],
 [942, 887364, 835896888],
 [943, 889249, 838561807],
 [944, 891136, 841232384],
 [945, 893025, 843908625],
 [946, 894916, 846590536],
 [947, 896809, 849278123],
 [948, 898704, 851971392],
 [949, 900601, 854670349],
 [950, 902500, 857375000],
 [951, 904401, 860085351],
 [952, 906304, 862801408],
 [953, 908209, 865523177],
 [954, 910116, 868250664],
 [955, 912025, 870983875],
 [956, 913936, 873722816],
 [957, 915849, 876467493],
 [958, 917764, 879217912],
 [959, 919681, 881974079],
 [960, 921600, 884736000],
 [961, 923521, 887503681],
 [962, 925444, 890277128],
 [963, 927369, 893056347],
 [964, 929296, 895841344],
 [965, 931225, 898632125],
 [966, 933156, 901428696],
 [967, 935089, 904231063],
 [968, 937024, 907039232],
 [969, 938961, 909853209],
 [970, 940900, 912673000],
 [971, 942841, 915498611],
 [972, 944784, 918330048],
 [973, 946729, 921167317],
 [974, 948676, 924010424],
 [975, 950625, 926859375],
 [976, 952576, 929714176],
 [977, 954529, 932574833],
 [978, 956484, 935441352],
 [979, 958441, 938313739],
 [980, 960400, 941192000],
 [981, 962361, 944076141],
 [982, 964324, 946966168],
 [983, 966289, 949862087],
 [984, 968256, 952763904],
 [985, 970225, 955671625],
 [986, 972196, 958585256],
 [987, 974169, 961504803],
 [988, 976144, 964430272],
 [989, 978121, 967361669],
 [990, 980100, 970299000],
 [991, 982081, 973242271],
 [992, 984064, 976191488],
 [993, 986049, 979146657],
 [994, 988036, 982107784],
 [995, 990025, 985074875],
 [996, 992016, 988047936],
 [997, 994009, 991026973],
 [998, 996004, 994011992],
 [999, 998001, 997002999],
 ...]
import pandas as pd
help(pd.read_csv)
Help on function read_csv in module pandas.io.parsers:

read_csv(filepath_or_buffer, sep=',', delimiter=None, header='infer', names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, skipfooter=None, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, iterator=False, chunksize=None, compression='infer', thousands=None, decimal='.', lineterminator=None, quotechar='"', quoting=0, escapechar=None, comment=None, encoding=None, dialect=None, tupleize_cols=False, error_bad_lines=True, warn_bad_lines=True, skip_footer=0, doublequote=True, delim_whitespace=False, as_recarray=False, compact_ints=False, use_unsigned=False, low_memory=True, buffer_lines=None, memory_map=False, float_precision=None)
    Read CSV (comma-separated) file into DataFrame
    
    Also supports optionally iterating or breaking of the file
    into chunks.
    
    Additional help can be found in the `online docs for IO Tools
    <http://pandas.pydata.org/pandas-docs/stable/io.html>`_.
    
    Parameters
    ----------
    filepath_or_buffer : str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)
        The string could be a URL. Valid URL schemes include http, ftp, s3, and
        file. For file URLs, a host is expected. For instance, a local file could
        be file ://localhost/path/to/table.csv
    sep : str, default ','
        Delimiter to use. If sep is None, will try to automatically determine
        this. Regular expressions are accepted and will force use of the python
        parsing engine and will ignore quotes in the data.
    delimiter : str, default None
        Alternative argument name for sep.
    header : int or list of ints, default 'infer'
        Row number(s) to use as the column names, and the start of the data.
        Default behavior is as if set to 0 if no ``names`` passed, otherwise
        ``None``. Explicitly pass ``header=0`` to be able to replace existing
        names. The header can be a list of integers that specify row locations for
        a multi-index on the columns e.g. [0,1,3]. Intervening rows that are not
        specified will be skipped (e.g. 2 in this example is skipped). Note that
        this parameter ignores commented lines and empty lines if
        ``skip_blank_lines=True``, so header=0 denotes the first line of data
        rather than the first line of the file.
    names : array-like, default None
        List of column names to use. If file contains no header row, then you
        should explicitly pass header=None
    index_col : int or sequence or False, default None
        Column to use as the row labels of the DataFrame. If a sequence is given, a
        MultiIndex is used. If you have a malformed file with delimiters at the end
        of each line, you might consider index_col=False to force pandas to _not_
        use the first column as the index (row names)
    usecols : array-like, default None
        Return a subset of the columns.
        Results in much faster parsing time and lower memory usage.
    squeeze : boolean, default False
        If the parsed data only contains one column then return a Series
    prefix : str, default None
        Prefix to add to column numbers when no header, e.g. 'X' for X0, X1, ...
    mangle_dupe_cols : boolean, default True
        Duplicate columns will be specified as 'X.0'...'X.N', rather than 'X'...'X'
    dtype : Type name or dict of column -> type, default None
        Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32}
        (Unsupported with engine='python'). Use `str` or `object` to preserve and
        not interpret dtype.
    engine : {'c', 'python'}, optional
        Parser engine to use. The C engine is faster while the python engine is
        currently more feature-complete.
    converters : dict, default None
        Dict of functions for converting values in certain columns. Keys can either
        be integers or column labels
    true_values : list, default None
        Values to consider as True
    false_values : list, default None
        Values to consider as False
    skipinitialspace : boolean, default False
        Skip spaces after delimiter.
    skiprows : list-like or integer, default None
        Line numbers to skip (0-indexed) or number of lines to skip (int)
        at the start of the file
    skipfooter : int, default 0
        Number of lines at bottom of file to skip (Unsupported with engine='c')
    nrows : int, default None
        Number of rows of file to read. Useful for reading pieces of large files
    na_values : str or list-like or dict, default None
        Additional strings to recognize as NA/NaN. If dict passed, specific
        per-column NA values.  By default the following values are interpreted as
        NaN: `''`, `'#N/A'`, `'#N/A N/A'`, `'#NA'`, `'-1.#IND'`, `'-1.#QNAN'`, `'-NaN'`, `'-nan'`, `'1.#IND'`, `'1.#QNAN'`, `'N/A'`, `'NA'`, `'NULL'`, `'NaN'`, `'nan'`.
    keep_default_na : bool, default True
        If na_values are specified and keep_default_na is False the default NaN
        values are overridden, otherwise they're appended to.
    na_filter : boolean, default True
        Detect missing value markers (empty strings and the value of na_values). In
        data without any NAs, passing na_filter=False can improve the performance
        of reading a large file
    verbose : boolean, default False
        Indicate number of NA values placed in non-numeric columns
    skip_blank_lines : boolean, default True
        If True, skip over blank lines rather than interpreting as NaN values
    parse_dates : boolean or list of ints or names or list of lists or dict, default False
    
        * boolean. If True -> try parsing the index.
        * list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3
          each as a separate date column.
        * list of lists. e.g.  If [[1, 3]] -> combine columns 1 and 3 and parse as
            a single date column.
        * dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call result
          'foo'
    
        Note: A fast-path exists for iso8601-formatted dates.
    infer_datetime_format : boolean, default False
        If True and parse_dates is enabled for a column, attempt to infer
        the datetime format to speed up the processing
    keep_date_col : boolean, default False
        If True and parse_dates specifies combining multiple columns then
        keep the original columns.
    date_parser : function, default None
        Function to use for converting a sequence of string columns to an array of
        datetime instances. The default uses ``dateutil.parser.parser`` to do the
        conversion. Pandas will try to call date_parser in three different ways,
        advancing to the next if an exception occurs: 1) Pass one or more arrays
        (as defined by parse_dates) as arguments; 2) concatenate (row-wise) the
        string values from the columns defined by parse_dates into a single array
        and pass that; and 3) call date_parser once for each row using one or more
        strings (corresponding to the columns defined by parse_dates) as arguments.
    dayfirst : boolean, default False
        DD/MM format dates, international and European format
    iterator : boolean, default False
        Return TextFileReader object for iteration or getting chunks with
        ``get_chunk()``.
    chunksize : int, default None
        Return TextFileReader object for iteration. `See IO Tools docs for more
        information
        <http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking>`_ on
        ``iterator`` and ``chunksize``.
    compression : {'infer', 'gzip', 'bz2', None}, default 'infer'
        For on-the-fly decompression of on-disk data. If 'infer', then use gzip or
        bz2 if filepath_or_buffer is a string ending in '.gz' or '.bz2',
        respectively, and no decompression otherwise. Set to None for no
        decompression.
    thousands : str, default None
        Thousands separator
    decimal : str, default '.'
        Character to recognize as decimal point (e.g. use ',' for European data).
    lineterminator : str (length 1), default None
        Character to break file into lines. Only valid with C parser.
    quotechar : str (length 1), optional
        The character used to denote the start and end of a quoted item. Quoted
        items can include the delimiter and it will be ignored.
    quoting : int or csv.QUOTE_* instance, default None
        Control field quoting behavior per ``csv.QUOTE_*`` constants. Use one of
        QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3).
        Default (None) results in QUOTE_MINIMAL behavior.
    escapechar : str (length 1), default None
        One-character string used to escape delimiter when quoting is QUOTE_NONE.
    comment : str, default None
        Indicates remainder of line should not be parsed. If found at the beginning
        of a line, the line will be ignored altogether. This parameter must be a
        single character. Like empty lines (as long as ``skip_blank_lines=True``),
        fully commented lines are ignored by the parameter `header` but not by
        `skiprows`. For example, if comment='#', parsing '#empty\na,b,c\n1,2,3'
        with `header=0` will result in 'a,b,c' being
        treated as the header.
    encoding : str, default None
        Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python
        standard encodings
        <https://docs.python.org/3/library/codecs.html#standard-encodings>`_
    dialect : str or csv.Dialect instance, default None
        If None defaults to Excel dialect. Ignored if sep longer than 1 char
        See csv.Dialect documentation for more details
    tupleize_cols : boolean, default False
        Leave a list of tuples on columns as is (default is to convert to
        a Multi Index on the columns)
    error_bad_lines : boolean, default True
        Lines with too many fields (e.g. a csv line with too many commas) will by
        default cause an exception to be raised, and no DataFrame will be returned.
        If False, then these "bad lines" will dropped from the DataFrame that is
        returned. (Only valid with C parser)
    warn_bad_lines : boolean, default True
        If error_bad_lines is False, and warn_bad_lines is True, a warning for each
        "bad line" will be output. (Only valid with C parser).
    
    Returns
    -------
    result : DataFrame or TextParser
df = pd.read_csv('../data/data_write_to_file.txt', 
                 sep = '\t', names = ['a', 'b', 'c'])
df[-5:]
a b c
9995 9995 99900025 998500749875
9996 9996 99920016 998800479936
9997 9997 99940009 999100269973
9998 9998 99960004 999400119992
9999 9999 99980001 999700029999

保存中间步骤产生的字典数据

import json
data_dict = {'a':1, 'b':2, 'c':3}
with open('../data/save_dict.json', 'w') as f:
    json.dump(data_dict, f)
dd = json.load(open("../data/save_dict.json"))
dd
{'a': 1, 'b': 2, 'c': 3}

重新读入json

保存中间步骤产生的列表数据

data_list = list(range(10))
with open('../data/save_list.json', 'w') as f:
    json.dump(data_list, f)
dl = json.load(open("../data/save_list.json"))
dl
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

使用matplotlib绘图

%matplotlib inline

import matplotlib.pyplot as plt
x = range(1, 100)
y = [i**-3 for i in x]
plt.plot(x, y, 'b-s')
plt.ylabel('$p(k)$', fontsize = 20)
plt.xlabel('$k$', fontsize = 20)
plt.xscale('log')
plt.yscale('log')
plt.title('Degree Distribution')
plt.show()
_images/03-python-intro_101_0.png
import numpy as np
# red dashes, blue squares and green triangles
t = np.arange(0., 5., 0.2)
plt.plot(t, t, 'r--')
plt.plot(t, t**2, 'bs')
plt.plot(t, t**3, 'g^')
plt.show()
_images/03-python-intro_102_0.png
# red dashes, blue squares and green triangles
t = np.arange(0., 5., 0.2)
plt.plot(t, t**2, 'b-s', label = '1')
plt.plot(t, t**2.5, 'r-o', label = '2')
plt.plot(t, t**3, 'g-^', label = '3')
plt.annotate(r'$\alpha = 3$', xy=(3.5, 40), xytext=(2, 80),
            arrowprops=dict(facecolor='black', shrink=0.05),
            fontsize = 20)
plt.ylabel('$f(t)$', fontsize = 20)
plt.xlabel('$t$', fontsize = 20)
plt.legend(loc=2,numpoints=1,fontsize=10)
plt.show()
# plt.savefig('/Users/chengjun/GitHub/cjc/figure/save_figure.png',
#             dpi = 300, bbox_inches="tight",transparent = True)
_images/03-python-intro_103_0.png
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(5,5))
sns.set(style="whitegrid")
plt.figure(1)
plt.subplot(221)
plt.plot(t, t, 'r--')
plt.text(2, 0.8*np.max(t), r'$\alpha = 1$', fontsize = 20)
plt.subplot(222)
plt.plot(t, t**2, 'bs')
plt.text(2, 0.8*np.max(t**2), r'$\alpha = 2$', fontsize = 20)
plt.subplot(223)
plt.plot(t, t**3, 'g^')
plt.text(2, 0.8*np.max(t**3), r'$\alpha = 3$', fontsize = 20)
plt.subplot(224)
plt.plot(t, t**4, 'r-o')
plt.text(2, 0.8*np.max(t**4), r'$\alpha = 4$', fontsize = 20)
plt.show()
_images/03-python-intro_105_0.png
def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo')
plt.plot(t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()
_images/03-python-intro_107_0.png
import matplotlib.gridspec as gridspec
import numpy as np

t = np.arange(0., 5., 0.2)

gs = gridspec.GridSpec(3, 3)
ax1 = plt.subplot(gs[0, :])
plt.plot(t, t**2, 'b-s')
ax2 = plt.subplot(gs[1,:-1])
plt.plot(t, t**2, 'g-s')
ax3 = plt.subplot(gs[1:, -1])
plt.plot(t, t**2, 'r-o')
ax4 = plt.subplot(gs[-1,0])
plt.plot(t, t**2, 'g-^')
ax5 = plt.subplot(gs[-1,1])
plt.plot(t, t**2, 'b-<')
plt.tight_layout()
_images/03-python-intro_108_0.png
def OLSRegressPlot(x,y,col,xlab,ylab):
    xx = sm.add_constant(x, prepend=True)
    res = sm.OLS(y,xx).fit()
    constant, beta = res.params
    r2 = res.rsquared
    lab = r'$\beta = %.2f, \,R^2 = %.2f$' %(beta,r2)
    plt.scatter(x,y,s=60,facecolors='none', edgecolors=col)
    plt.plot(x,constant + x*beta,"red",label=lab)
    plt.legend(loc = 'upper left',fontsize=16)
    plt.xlabel(xlab,fontsize=26)
    plt.ylabel(ylab,fontsize=26)
x = np.random.randn(50)
y = np.random.randn(50) + 3*x
pearsonr(x, y)
fig = plt.figure(figsize=(10, 4),facecolor='white')
OLSRegressPlot(x,y,'RoyalBlue',r'$x$',r'$y$')
plt.show()
_images/03-python-intro_110_0.png
fig = plt.figure(figsize=(7, 4),facecolor='white')
data = norm.rvs(10.0, 2.5, size=5000)
mu, std = norm.fit(data)
plt.hist(data, bins=25, normed=True, alpha=0.6, color='g')
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
plt.plot(x, p, 'r', linewidth=2)
title = r"$\mu = %.2f, \,  \sigma = %.2f$" % (mu, std)
plt.title(title,size=16)
plt.show()
_images/03-python-intro_111_0.png
import pandas as pd
df = pd.read_csv('../data/data_write_to_file.txt', sep = '\t', names = ['a', 'b', 'c'])
df[:5]
a b c
0 0 0 0
1 1 1 1
2 2 4 8
3 3 9 27
4 4 16 64
df.plot.line()
plt.yscale('log')
plt.ylabel('$values$', fontsize = 20)
plt.xlabel('$index$', fontsize = 20)
plt.show()
_images/03-python-intro_113_0.png
df.plot.scatter(x='a', y='b')
plt.show()
_images/03-python-intro_114_0.png
df.plot.hexbin(x='a', y='b', gridsize=25)
plt.show()
_images/03-python-intro_115_0.png
df['a'].plot.kde()
plt.show()
_images/03-python-intro_116_0.png
bp = df.boxplot()
plt.yscale('log')
plt.show()
/Users/chengjun/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:1: FutureWarning: 
The default value for 'return_type' will change to 'axes' in a future release.
 To use the future behavior now, set return_type='axes'.
 To keep the previous behavior and silence this warning, set return_type='dict'.
  if __name__ == '__main__':
_images/03-python-intro_117_1.png
df['c'].diff().hist()
plt.show()
_images/03-python-intro_118_0.png
df.plot.hist(stacked=True, bins=20)
# plt.yscale('log')
plt.show()
_images/03-python-intro_119_0.png

To be a programmer is to develop a carefully managed relationship with error. There’s no getting around it. You either make your accommodations with failure, or the work will become intolerable.

Ellen Ullman (an American computer programmer and author)

This is the end.

Thank you for your attention.