Not on PyPI yet. Install:
git clone https://github.com/AnswerDotAI/basedtab.git
pip install -e .read_csv and save_csv
from basedtab.core import BFrame
bf = BFrame.read_csv(path)
bf.head(2).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 |
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.groupby("Gender", ["Age", "Income"], mean=MEAN, rmse=RMSE)┌→───────────────────────────┐
↓"Male"⌷ │
↓ Age Income│
│mean 44.9126253 95670.2472│
│rmse 46.37557969 98752.06754│
│ │
│"Female"⌷ │
│ Age Income│
│mean 44.99776435 85660.92184│
│rmse 46.46704189 89097.22374│
└~───────────────────────────┘
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│
└~───────────────┘
ts.plot(title="Time Series")bf["Income"].hist(title="Income Distribution")