SHARE
TWEET

Untitled

a guest Jun 18th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. d = {'A':list(range(1000)), 'B':list(range(1000))}
  2. df=pd.DataFrame(d)
  3.      
  4. a = df.index.values[:-1]
  5. for i in a:
  6.     print(df.iloc[i:i+2])
  7.      
  8. ...
  9.        A    B
  10. 996  996  996
  11. 997  997  997
  12.        A    B
  13. 997  997  997
  14. 998  998  998
  15.        A    B
  16. 998  998  998
  17. 999  999  999
  18.      
  19. d = {'A':list(range(5)), 'B':list(range(5))}
  20. df=pd.DataFrame(d)
  21.  
  22. print (np.arange(len(df)) // 2)
  23. [0 0 1 1 2]
  24.  
  25. for i, g in df.groupby(np.arange(len(df)) // 2):
  26.     print (g)
  27.  
  28.    A  B
  29. 0  0  0
  30. 1  1  1
  31.    A  B
  32. 2  2  2
  33. 3  3  3
  34.    A  B
  35. 4  4  4
  36.      
  37. def chunker1(seq, size):
  38.     return (seq.iloc[pos:pos + size] for pos in range(0, len(seq)-1))
  39.  
  40. for i in chunker1(df,2):
  41.     print (i)
  42.  
  43.    A  B
  44. 0  0  0
  45. 1  1  1
  46.    A  B
  47. 1  1  1
  48. 2  2  2
  49.    A  B
  50. 2  2  2
  51. 3  3  3
  52.    A  B
  53. 3  3  3
  54. 4  4  4
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top