Tutorial by Examples: er

data(AirPassengers) class(AirPassengers) 1 "ts" In the spirit of Exploratory Data Analysis (EDA) a good first step is to look at a plot of your time-series data: plot(AirPassengers) # plot the raw data abline(reg=lm(AirPassengers~time(AirPassengers))) # fit a trend line For...
generate sample DF In [39]: df = pd.DataFrame(np.random.randint(0, 10, size=(5, 6)), columns=['a10','a20','a25','b','c','d']) In [40]: df Out[40]: a10 a20 a25 b c d 0 2 3 7 5 4 7 1 3 1 5 7 2 6 2 7 4 9 0 8 7 3 5 8 8 9 6 8 4 8 1 ...
from datetime import datetime import pandas_datareader.data as wb stocklist = ['AAPL','GOOG','FB','AMZN','COP'] start = datetime(2016,6,8) end = datetime(2016,6,11) p = wb.DataReader(stocklist, 'yahoo',start,end) p - is a pandas panel, with which we can do funny things: let's see what...
import os import glob import pandas as pd def get_merged_csv(flist, **kwargs): return pd.concat([pd.read_csv(f, **kwargs) for f in flist], ignore_index=True) path = 'C:/Users/csvfiles' fmask = os.path.join(path, '*mask*.csv') df = get_merged_csv(glob.glob(fmask), index_col=None, use...
You can iterate on the object returned by groupby(). The iterator contains (Category, DataFrame) tuples. # Same example data as in the previous example. import numpy as np import pandas as pd np.random.seed(0) df = pd.DataFrame({'Age': np.random.randint(20, 70, 100), 'Sex':...
Consider the utility class pattern: a class with only static methods and no fields. It's recommended to prevent instantiation of such classes by adding a private a constructor. This live template example makes it easy to add a private constructor to an existing class, using the name of the enclos...
You can join (concatenate) binaries (including strings) and lists: iex(1)> [1, 2, 3] ++ [4, 5] [1, 2, 3, 4, 5] iex(2)> [1, 2, 3, 4, 5] -- [1, 3] [2, 4, 5] iex(3)> "qwe" <> "rty" "qwerty"
in operator allows you to check whether a list or a range includes an item: iex(4)> 1 in [1, 2, 3, 4] true iex(5)> 0 in (1..5) false
As a non-standard extension to C++, common compilers allow the use of classes as anonymous members. struct Example { struct { int inner_b; }; int outer_b; //The anonymous struct's members are accessed as if members of the parent struct Example() : inner...
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; use std::collections::BTreeMap as Map; #[derive(Serialize)] struct Resource { // Always serialized. name: String, // Never serialized. #[serde(skip_serializing)] hash: String, ...
mutable modifier in this context is used to indicate that a data field of a const object may be modified without affecting the externally-visible state of the object. If you are thinking about caching a result of expensive computation, you should probably use this keyword. If you have a lock (for ...
Maps and keyword lists have different application. For instance, a map cannot have two keys with the same value and it's not ordered. Conversely, a Keyword list can be a little bit hard to use in pattern matching in some cases. Here's a few use cases for maps vs keyword lists. Use keyword lists wh...
You can generate a rails migration file from the terminal using the following command: rails generate migration NAME [field[:type][:index] field[:type][:index]] [options] For a list of all the options supported by the command, you could run the command without any arguments as in rails generate ...
Let's say we need to add a button for each piece of loadedData array (for instance, each button should be a slider showing the data; for the sake of simplicity, we'll just alert a message). One may try something like this: for(var i = 0; i < loadedData.length; i++) jQuery("#container&q...
create-react-app is a React app boilerplate generator created by Facebook. It provides a development environment configured for ease-of-use with minimal setup, including: ES6 and JSX transpilation Dev server with hot module reloading Code linting CSS auto-prefixing Build script with JS, CSS ...
The cmath module is similar to the math module, but defines functions appropriately for the complex plane. First of all, complex numbers are a numeric type that is part of the Python language itself rather than being provided by a library class. Thus we don't need to import cmath for ordinary arith...
Erlang modules are available as atoms. For example, the Erlang math module is available as :math: iex> :math.pi 3.141592653589793
Use module_info on Erlang modules you wish to inspect: iex> :math.module_info [module: :math, exports: [pi: 0, module_info: 0, module_info: 1, pow: 2, atan2: 2, sqrt: 1, log10: 1, log2: 1, log: 1, exp: 1, erfc: 1, erf: 1, atanh: 1, atan: 1, asinh: 1, asin: 1, acosh: 1, acos: 1, tanh...
Use keyword lists for 'options'-style parameters that contains multiple key-value pairs: def myfunc(arg1, opts \\ []) do # Function body end We can call the function above like so: iex> myfunc "hello", pizza: true, soda: false which is equivalent to: iex> myfunc("he...
class Vector { double x double y } def points = [ new Vector(x: 10, y: -5), new Vector(x: -17.5, y: 3), new Vector(x: -3.3, y: -1) ] assert points*.x == [10, -17.5, -3.3] Note: The * is optional. We could also write the above statement as in the below line and Groov...

Page 111 of 417