Tutorial by Examples: f

In [1]: df1 = pd.DataFrame({'x': [1, 2, 3], 'y': ['a', 'b', 'c']}) In [2]: df2 = pd.DataFrame({'y': ['b', 'c', 'd'], 'z': [4, 5, 6]}) In [3]: df1 Out[3]: x y 0 1 a 1 2 b 2 3 c In [4]: df2 Out[4]: y z 0 b 4 1 c 5 2 d 6 Inner join: Uses the intersection ...
When you inherit from a class with a property, you can provide a new implementation for one or more of the property getter, setter or deleter functions, by referencing the property object on the parent class: class BaseClass(object): @property def foo(self): return some_calculate...
we can annotate fields with @BindView and a view ID for Butter Knife to find and automatically cast the corresponding view in our layout. Binding Views Binding Views in Activity class ExampleActivity extends Activity { @BindView(R.id.title) TextView title; @BindView(R.id.subtitle) TextView ...
CLP(FD) constraints (Finite Domains) implement arithmetic over integers. They are available in all serious Prolog implementations. There are two major use cases of CLP(FD) constraints: Declarative integer arithmetic Solving combinatorial problems such as planning, scheduling and allocation task...
The predicate dif/2 is a pure predicate: It can be used in all directions and with all instantiation patterns, always meaning that its two arguments are different.
List doesn't support "random access", which means it takes more work to get, say, the fifth element from the list than the first element, and as a result there's no List.get nth list function. One has to go all the way from the beginning (1 -> 2 -> 3 -> 4 -> 5). If you need ra...
Usually authentication&authorization processes are performed by built-in cookie and token supports in .net MVC. But if you decide to do it yourself with Session you can use below logic for both page requests and ajax requests. public class SessionControl : ActionFilterAttribute { public o...
This is an example of how to use the generic type TFood inside Eat method on the class Animal public interface IFood { void EatenBy(Animal animal); } public class Grass: IFood { public void EatenBy(Animal animal) { Console.WriteLine("Grass was eaten by: {0}",...
letters = list('abcde') Select three letters randomly (with replacement - same item can be chosen multiple times): np.random.choice(letters, 3) ''' Out: array(['e', 'e', 'd'], dtype='<U1') ''' Sampling without replacement: np.random.choice(letters, 3, replace=False) ''' Out...
Draw samples from a normal (gaussian) distribution # Generate 5 random numbers from a standard normal distribution # (mean = 0, standard deviation = 1) np.random.randn(5) # Out: array([-0.84423086, 0.70564081, -0.39878617, -0.82719653, -0.4157447 ]) # This result can also be achieved with t...
In the condition of the for and while loops, it's also permitted to declare an object. This object will be considered to be in scope until the end of the loop, and will persist through each iteration of the loop: for (int i = 0; i < 5; ++i) { do_something(i); } // i is no longer in scope...
The following method computes the Nth Fibonacci number using recursion. public int fib(final int n) { if (n > 2) { return fib(n - 2) + fib(n - 1); } return 1; } The method implements a base case (n <= 2) and a recursive case (n>2). This illustrates the use of re...
Overload resolution partitions the cost of passing an argument to a parameter into one of four different categorizes, called "sequences". Each sequence may include zero, one or several conversions Standard conversion sequence void f(int a); f(42); User defined conversion seque...
Start a named process on one IP address: $ iex --name [email protected] --cookie chocolate iex([email protected])> Node.ping :"[email protected]" :pong iex([email protected])> Node.list [:"[email protected]"] Start another named process on a different IP address: $ iex ...
A factory function is simply a function that returns an object. Factory functions do not require the use of the new keyword, but can still be used to initialize an object, like a constructor. Often, factory functions are used as API wrappers, like in the cases of jQuery and moment.js, so users do ...
Files and directories (another name for folders) are at the heart of Linux, so being able to create, view, move, and delete them from the command line is very important and quite powerful. These file manipulation commands allow you to perform the same tasks that a graphical file explorer would perfo...
By recursion let rec sumTotal list = match list with | [] -> 0 // empty list -> return 0 | head :: tail -> head + sumTotal tail The above example says: "Look at the list, is it empty? return 0. Otherwise it is a non-empty list. So it could be [1], [1; 2], [1; 2; 3] ...
Code that uses generics has many benefits over non-generic code. Below are the main benefits Stronger type checks at compile time A Java compiler applies strong type checking to generic code and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runt...
To filter a slice without allocating a new underlying array: // Our base slice slice := []int{ 1, 2, 3, 4 } // Create a zero-length slice with the same underlying array tmp := slice[:0] for _, v := range slice { if v % 2 == 0 { // Append desired values to slice tmp = append(tmp, ...
fn foo<'a>(x: &'a u32) { // ... } This specifies that foo has lifetime 'a, and the parameter x must have a lifetime of at least 'a. Function lifetimes are usually omitted through lifetime elision: fn foo(x: &u32) { // ... } In the case that a function takes multiple ...

Page 82 of 457