Skip to content
AnswerDotAIPublic

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

BasedTab

Usage

Installation

Not on PyPI yet. Install:

git clone https://github.com/AnswerDotAI/basedtab.git
pip install -e .

How to use

Load data

read_csv and save_csv

from basedtab.core import *
from nbdev.config import get_config

data_path = str(get_config().config_path/'data/toy.csv')
bf = BFrame.read_csv(data_path)
bf.head(3).df
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Number City Gender Age Income Illness
0 1 Dallas Male 41 40367.0 No
1 2 Dallas Male 54 45084.0 No
2 3 Dallas Male 42 52483.0 No

Groupby

from basedpl import add, tally, square
MEAN = add.reduce_first / tally
bf.groupby("City", "Income", mean=MEAN)
┌→─────────────────┐
↓"Dallas"⌷         │
↓          Income  │
│mean 45252.23119  │
│                  │
│"New York City"⌷  │
│          Income  │
│mean 96857.13139  │
│                  │
│"Los Angeles"⌷    │
│          Income  │
│mean 95264.15541  │
│                  │
│"Mountain View"⌷  │
│          Income  │
│mean 135078.4158  │
│                  │
│"Boston"⌷         │
│         Income   │
│mean 91554.5715   │
│                  │
│"Washington D.C."⌷│
│          Income  │
│mean 70991.61281  │
│                  │
│"San Diego"⌷      │
│          Income  │
│mean 100756.2092  │
│                  │
│"Austin"⌷         │
│          Income  │
│mean 90277.51342  │
└~─────────────────┘
RMSE = MEAN.under(square)
bf.head(100).groupby("Gender", ["Age", "Income"], mean=MEAN, rmse=RMSE)
┌→───────────────────────────┐
↓"Male"⌷                     │
↓             Age      Income│
│mean 44.57407407 48301.42593│
│rmse 45.66970793 49632.10639│
│                            │
│"Female"⌷                   │
│             Age      Income│
│mean 45.30434783 39739.36957│
│rmse 46.73468128 40738.65853│
└~───────────────────────────┘

Rolling

ts = BFrame(dict(price=[5,4.3,4.1,2,10,20,15,25]))
ts
┌→────────────────────────────────┐
│ price:┌→──────────────────────┐ │
│       │5 4.3 4.1 2 10 20 15 25│ │
│       └~──────────────────────┘ │
└∊────────────────────────────────┘
ts.rolling("price", size=3, edge="clamp", mean=MEAN)
┌→───────────────┐
↓0⌷              │
↓           price│
│mean 4.766666667│
│                │
│1⌷              │
│           price│
│mean 4.466666667│
│                │
│2⌷              │
│           price│
│mean 3.466666667│
│                │
│3⌷              │
│           price│
│mean 5.366666667│
│                │
│4⌷              │
│           price│
│mean 10.66666667│
│                │
│5⌷              │
│     price      │
│mean    15      │
│                │
│6⌷              │
│     price      │
│mean    20      │
│                │
│7⌷              │
│           price│
│mean 21.66666667│
└~───────────────┘
ts.rolling("price", size=2, step=2, mean=MEAN, rmse=RMSE)
┌→───────────────┐
↓0⌷              │
↓           price│
│mean        4.65│
│rmse 4.663153439│
│                │
│1⌷              │
│           price│
│mean        3.05│
│rmse 3.225678223│
│                │
│2⌷              │
│          price │
│mean         15 │
│rmse 15.8113883 │
│                │
│3⌷              │
│           price│
│mean          20│
│rmse 20.61552813│
└~───────────────┘

Plot

ts.plot(title="Time Series")

bf["Income"].hist(title="Income Distribution")

Contributors

Languages