- 
      
- 
        Save arc279/afb7463fe03fc08981d6090f6a079b6e to your computer and use it in GitHub Desktop. 
    pickleに追記と読み出し
  
        
  
    
      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 pickle | |
| def dump_seq(r, of): | |
| with open(of, "wb") as f: | |
| pickle.dump(next(r), f) | |
| try: | |
| while True: | |
| with open(of, "ab") as f: | |
| pickle.dump(next(r), f) | |
| except StopIteration as e: | |
| pass | |
| def load_seq(fp): | |
| try: | |
| while True: | |
| yield pickle.load(f) | |
| except EOFError as e: | |
| raise StopIteration(e) | |
| # https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv | |
| r = pd.read_csv(open("iris.csv"), chunksize=20) | |
| dump_seq(r, "o") | |
| with open("o", "rb") as f: | |
| for i, x in enumerate(load_seq(f)): | |
| print(i, x) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment