Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- #
- # Filter rows by strings with date and time.
- # It will not work if date is in format 04-06-2018 .
- #
- text = '''
- 293 2018-06-14 14:55 1832.15 1833.40 1831.90 1833.35 37947
- 294 2018-06-14 15:00 1833.40 1834.95 1833.30 1834.90 106271
- 295 2018-06-14 15:05 1834.95 1835.05 1834.40 1834.85 102107
- 296 2018-06-14 15:10 1834.80 1834.85 1832.95 1833.80 95931
- 297 2018-06-14 15:15 1833.75 1834.85 1833.05 1834.85 124639
- 298 2018-06-14 15:20 1834.85 1834.85 1831.55 1832.50 121206
- '''
- data = [line.split() for line in text.split('\n') if line.strip()]
- df = pd.DataFrame(data, columns=['index', 'Date','Time','open','high','low','close','volume'])
- df.set_index('index')
- d1 = '2018-06-14'
- t1 = '15:00'
- t2 = '15:15'
- new_df = df[ (df["Date"] == d1) & (df["Time"] == t1) ]
- print(new_df)
- new_df = df[ (df["Date"] == d1) & (df["Time"] >= t1) & (df["Time"] <= t2) ]
- print(new_df)
- print(new_df["high"].max())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement