Converts historical data matrix to a pandas dataframe. Args: historical_data (list): A matrix of historical OHCLV data. Returns: pandas.DataFrame: Contains the historical data in a pandas dataframe.
(self, historical_data)
| 16 | |
| 17 | |
| 18 | def convert_to_dataframe(self, historical_data): |
| 19 | """Converts historical data matrix to a pandas dataframe. |
| 20 | |
| 21 | Args: |
| 22 | historical_data (list): A matrix of historical OHCLV data. |
| 23 | |
| 24 | Returns: |
| 25 | pandas.DataFrame: Contains the historical data in a pandas dataframe. |
| 26 | """ |
| 27 | |
| 28 | dataframe = pandas.DataFrame(historical_data) |
| 29 | dataframe.transpose() |
| 30 | |
| 31 | dataframe.columns = ['timestamp', 'open', 'high', 'low', 'close', 'volume'] |
| 32 | dataframe['datetime'] = dataframe.timestamp.apply( |
| 33 | lambda x: pandas.to_datetime(datetime.fromtimestamp(x / 1000).strftime('%c')) |
| 34 | ) |
| 35 | |
| 36 | dataframe.set_index('datetime', inplace=True, drop=True) |
| 37 | dataframe.drop('timestamp', axis=1, inplace=True) |
| 38 | |
| 39 | return dataframe |
no outgoing calls
no test coverage detected