diff options
author | Théo de la Hogue | 2022-05-03 16:39:32 +0200 |
---|---|---|
committer | Théo de la Hogue | 2022-05-03 16:39:32 +0200 |
commit | 025f24474e203f42241b46403b708766463d38b0 (patch) | |
tree | 8639b08a8aa0b0eb0b928445d4d1782e0538799e /src | |
parent | 9bc7c5224e0dce38933b4f8ba033b7c5b1ff4f43 (diff) | |
download | argaze-025f24474e203f42241b46403b708766463d38b0.zip argaze-025f24474e203f42241b46403b708766463d38b0.tar.gz argaze-025f24474e203f42241b46403b708766463d38b0.tar.bz2 argaze-025f24474e203f42241b46403b708766463d38b0.tar.xz |
Adding a method to convert a TimeStampedbuffer into panda dataframe.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/DataStructures.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index 7b6ad9b..b1b47f5 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -100,22 +100,28 @@ class TimeStampedBuffer(collections.OrderedDict): return None def export_as_json(self, filepath): - """Write buffer content into a json file""" + """Write buffer content into a json file.""" try: with open(filepath, 'w', encoding='utf-8') as jsonfile: json.dump(self, jsonfile, ensure_ascii = False, default=vars) except: raise RuntimeError(f'Can\' write {filepath}') + def as_dataframe(self, exclude=[]): + """Convert buffer as pandas dataframe.""" + + df = pandas.DataFrame.from_dict(self.values()) + df.drop(exclude, inplace=True, axis=True) + df['timestamp'] = self.keys() + df.set_index('timestamp', inplace=True) + + return df + def export_as_csv(self, filepath, exclude=[]): - """Write buffer content into a csv file""" + """Write buffer content into a csv file.""" try: - df = pandas.DataFrame.from_dict(self.values()) - df.drop(exclude, inplace=True, axis=True) - df['timestamp'] = self.keys() - df.set_index('timestamp', inplace=True) - df.to_csv(filepath, index=True) + self.as_dataframe(exclude=exclude).to_csv(filepath, index=True) except: raise RuntimeError(f'Can\' write {filepath}') |