mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-16 13:42:24 -04:00
31 lines
No EOL
788 B
Python
31 lines
No EOL
788 B
Python
# -*- encoding: utf-8 -*-
|
|
# This class implements plot scripts
|
|
# author: steinkirch
|
|
|
|
import pandas as pd
|
|
from utils.os import exit_with_error
|
|
|
|
|
|
def open_csv(filepath) -> dict:
|
|
"""Load and parse a csv file."""
|
|
|
|
try:
|
|
return pd.read_csv(filepath)
|
|
except (IOError, FileNotFoundError, TypeError) as e:
|
|
exit_with_error(f'Failed to parse: "{filepath}": {e}')
|
|
|
|
|
|
def save_csv(destination, data, index=False) -> None:
|
|
"""Save data from memory to a csv destination in disk."""
|
|
|
|
try:
|
|
data.to_csv(destination, index=index)
|
|
|
|
except (IOError, TypeError) as e:
|
|
log_error(f'Could not save {destination}: {e}')
|
|
|
|
|
|
def plot_bar(y, x) -> None:
|
|
"""Simplest plot for two sets."""
|
|
df = pd.DataFrame(y, index=x)
|
|
df.plot.bar(rot=0, subplots=True) |