red_amber 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,188 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# RedAmber Examples\n",
8
- "\n",
9
- "This notebook walks through the [README of RedAmber](https://github.com/heronshoes/red_amber#readme)."
10
- ]
11
- },
12
- {
13
- "cell_type": "markdown",
14
- "metadata": {},
15
- "source": [
16
- "## `RedAmber::DataFrame`"
17
- ]
18
- },
19
- {
20
- "cell_type": "code",
21
- "execution_count": null,
22
- "metadata": {
23
- "tags": []
24
- },
25
- "outputs": [],
26
- "source": [
27
- "require 'red_amber'\n",
28
- "include RedAmber\n",
29
- "require 'datasets-arrow'\n",
30
- "\n",
31
- "{RedAmber: VERSION, Datasets: Datasets::VERSION}"
32
- ]
33
- },
34
- {
35
- "cell_type": "markdown",
36
- "metadata": {},
37
- "source": [
38
- "## Example: diamonds dataset\n",
39
- "\n",
40
- "For the first loading of Datasets::Diamonds, it will take some time to download."
41
- ]
42
- },
43
- {
44
- "cell_type": "code",
45
- "execution_count": null,
46
- "metadata": {
47
- "tags": []
48
- },
49
- "outputs": [],
50
- "source": [
51
- "dataset = Datasets::Diamonds.new\n",
52
- "diamonds = DataFrame.new(dataset)"
53
- ]
54
- },
55
- {
56
- "cell_type": "code",
57
- "execution_count": null,
58
- "metadata": {
59
- "tags": []
60
- },
61
- "outputs": [],
62
- "source": [
63
- "df = diamonds\n",
64
- " .slice { carat > 1 } # or use #filter instead of #slice\n",
65
- " .group(:cut)\n",
66
- " .mean(:price) # `pick` prior to `group` is not required if `:price` is specified here.\n",
67
- " .sort('-mean(price)')"
68
- ]
69
- },
70
- {
71
- "cell_type": "code",
72
- "execution_count": null,
73
- "metadata": {
74
- "tags": []
75
- },
76
- "outputs": [],
77
- "source": [
78
- "usdjpy = 110.0 # when the yen was stronger\n",
79
- "\n",
80
- "df.rename('mean(price)': :mean_price_USD)\n",
81
- " .assign(:mean_price_JPY) { mean_price_USD * usdjpy }"
82
- ]
83
- },
84
- {
85
- "cell_type": "markdown",
86
- "metadata": {
87
- "tags": []
88
- },
89
- "source": [
90
- "## Example: starwars dataset"
91
- ]
92
- },
93
- {
94
- "cell_type": "code",
95
- "execution_count": null,
96
- "metadata": {
97
- "tags": []
98
- },
99
- "outputs": [],
100
- "source": [
101
- "uri = URI('https://vincentarelbundock.github.io/Rdatasets/csv/dplyr/starwars.csv')\n",
102
- "\n",
103
- "starwars = DataFrame.load(uri)"
104
- ]
105
- },
106
- {
107
- "cell_type": "code",
108
- "execution_count": null,
109
- "metadata": {
110
- "tags": []
111
- },
112
- "outputs": [],
113
- "source": [
114
- "starwars\n",
115
- " .drop(0) # delete unnecessary index column\n",
116
- " .remove { species == \"NA\" } # delete unnecessary rows\n",
117
- " .group(:species) { [count(:species), mean(:height, :mass)] }\n",
118
- " .slice { count > 1 } # or use #filter instead of slice"
119
- ]
120
- },
121
- {
122
- "cell_type": "markdown",
123
- "metadata": {},
124
- "source": [
125
- "## `RedAmber::Vector`"
126
- ]
127
- },
128
- {
129
- "cell_type": "code",
130
- "execution_count": null,
131
- "metadata": {
132
- "tags": []
133
- },
134
- "outputs": [],
135
- "source": [
136
- "penguins = DataFrame.new(Datasets::Penguins.new)"
137
- ]
138
- },
139
- {
140
- "cell_type": "code",
141
- "execution_count": null,
142
- "metadata": {
143
- "tags": []
144
- },
145
- "outputs": [],
146
- "source": [
147
- "penguins[:bill_length_mm]"
148
- ]
149
- },
150
- {
151
- "cell_type": "code",
152
- "execution_count": null,
153
- "metadata": {
154
- "tags": []
155
- },
156
- "outputs": [],
157
- "source": [
158
- "penguins[:bill_length_mm] < 40"
159
- ]
160
- },
161
- {
162
- "cell_type": "code",
163
- "execution_count": null,
164
- "metadata": {
165
- "tags": []
166
- },
167
- "outputs": [],
168
- "source": [
169
- "penguins[:bill_length_mm].mean"
170
- ]
171
- }
172
- ],
173
- "metadata": {
174
- "kernelspec": {
175
- "display_name": "Ruby 3.0.2",
176
- "language": "ruby",
177
- "name": "ruby"
178
- },
179
- "language_info": {
180
- "file_extension": ".rb",
181
- "mimetype": "application/x-ruby",
182
- "name": "ruby",
183
- "version": "3.0.2"
184
- }
185
- },
186
- "nbformat": 4,
187
- "nbformat_minor": 4
188
- }