Skip to content

Instantly share code, notes, and snippets.

@pbrumblay
Last active September 29, 2020 04:34
Show Gist options
  • Save pbrumblay/b8fee2a425be6bfc88fc43ff15fb0199 to your computer and use it in GitHub Desktop.
Save pbrumblay/b8fee2a425be6bfc88fc43ff15fb0199 to your computer and use it in GitHub Desktop.
Add row to pandas_ta dataframe and recompute
import pandas as pd
import pandas_ta as ta
from dateutil import parser
df = pd.read_csv('AUD_CAD.csv', sep=',', names=[
'datetime', 'bid_open', 'bid_high', 'bid_low', 'bid_close', 'ask_open', 'ask_high', 'ask_low', 'ask_close', 'mid_open', 'mid_high', 'mid_low', 'mid_close', 'volume'], error_bad_lines=False, parse_dates=['datetime'])
df.ta.atr(append=True, high='bid_high', low='bid_low', close='bid_close')
print(df)
newdt = parser.isoparse('2020-08-11 21:00:00+00:00')
newrow = {'datetime': newdt, 'bid_open': 0.94971, 'bid_low': 0.94955, 'bid_high': 0.94982, 'bid_close': 0.94969, 'ask_open': 0.94973, 'ask_high': 0.95532,
'ask_low': 0.94957, 'ask_close': 0.95031, 'mid_open': 0.95472, 'mid_high': 0.95738, 'mid_low': 0.94949, 'mid_close': 0.94998, 'volume': 112333}
df = df.append(newrow, ignore_index=True)
df.ta.atr(append=True, high='bid_high', low='bid_low', close='bid_close')
print(df)
@pbrumblay
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment