This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##get specific field from list of list | |
| names <- unlist ( lapply( mle, function(x){x$name} )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bi/env python | |
| class OnlyOne: | |
| """delegate object creation to a private nested class""" | |
| class __OnlyOne: #naming strting with __ user cannot access | |
| def __init__(self,arg): | |
| self.val = arg | |
| def __str__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # a simple static factory method | |
| from __future__ import generators | |
| import random | |
| import math | |
| class Shape(object): #base abstract class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## case 1 | |
| >>> import pyarrow.parquet as pq | |
| >>> dataset = pq.ParquetDataset('.') | |
| >>> dataset.read_pandas() | |
| #compare to case 2 | |
| >>> from glob import glob | |
| >>> from fastparquet import ParquetFile | |
| >>> paths = glob('*.parquet) | |
| >>> pf = ParquetFile(paths) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fastparquet | |
| ######################## | |
| # read 1 file # | |
| ######################## | |
| src_file='/tmp/file.pq' | |
| pqf = fastparquet.ParquetFile(src_file) | |
| s = timeit.default_timer() | |
| df = pqf.to_pandas(columns=None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def recur_factorial(n): | |
| if n == 1: | |
| return n | |
| else: | |
| return n*recur_factorial(n-1) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from pprint import pprint as pp | |
| ### create numpy array | |
| mylist=[1,2,3,4] | |
| ar=np.array(mylist) | |
| type(mylist) #stil a list | |
| type(ar) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| panda_basic.py | |
| import pandas as pd | |
| import numpy as np | |
| from pprint import pprint as pp | |
| # Create an example dataframe | |
| data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy', 'Jason'], | |
| 'year': [2012, 2012, 2013, 2014, 2014, 2015], | |
| 'reports': [4, 24, 31, 2, 3, 0]} | |
| df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma', 'Moscow']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| from pprint import pprint as pp | |
| data = {'name': ['Jason', 'Molly', 'Tina', np.nan, 'Amy', 'Jason'], | |
| 'year': [2012, 2012, 2013, 2014, 2014, 2015], | |
| 'born': [pd.NaT, pd.NaT, pd.Timestamp('1940-04-25'), pd.NaT, pd.Timestamp('1973-03-25'), pd.NaT], | |
| 'reports': [4, 24, 31, 2, 3, np.nan]} | |
| df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma', 'Moscow']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import datetime | |
| from pprint import pprint as pp | |
| data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy', 'Jason'], | |
| 'year': [2012, 2012, 2013, 2014, 2014, 2015], | |
| 'week': ['2012-01-01','2012-01-01','2013-01-01','2014-01-01','2014-01-01','2015-01-01'], |
OlderNewer