Guest User

Untitled

a guest
Jan 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def random_dates(start, end, n=10):
  2. start_u = start.value//10**9
  3. end_u = end.value//10**9
  4. return pd.to_datetime(np.random.randint(start_u, end_u, n), unit='s')
  5.  
  6. np.random.seed(0)
  7. df = pd.DataFrame(np.random.random(3255000).reshape(465000,7)) # same shape as my data
  8. df['date'] = random_dates(pd.to_datetime('1990-01-01'), pd.to_datetime('2018-01-01'), 465000)
  9. df = df.set_index([0, 'date'])
  10. df = df.sort_values(by=[3]) # unsort indices, just in case
  11. df.index.lexsort_depth
  12. > 0
  13. df.index.is_monotonic()
  14. > False
  15. df.loc[(0.9987185534991936, pd.to_datetime('2012-04-16 07:04:34'))]
  16. # no warning
Add Comment
Please, Sign In to add comment