aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/DataStructures.py20
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}')