mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 22:20:22 -04:00
💾
This commit is contained in:
parent
0696b08d04
commit
314bdf533e
94 changed files with 11 additions and 7 deletions
32
web3-toolkit/scripts/utils/plots.py
Normal file
32
web3-toolkit/scripts/utils/plots.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
# This class implements plot scripts
|
||||
# author: steinkirch
|
||||
|
||||
import pandas as pd
|
||||
from utils.os import exit_with_error, log_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)
|
Loading…
Add table
Add a link
Reference in a new issue