Tutorial by Examples

You can open several content managers at the same time: with open(input_path) as input_file, open(output_path, 'w') as output_file: # do something with both files. # e.g. copy the contents of input_file into output_file for line in input_file: output_file.write(line...
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...
Install the necessary Python Library via: $ pip install elasticsearch Connect to Elasticsearch, Create a Document (e.g. data entry) and "Index" the document using Elasticsearch. from datetime import datetime from elasticsearch import Elasticsearch # Connect to Elasticsearch using ...
Example uses basic HTTP syntax. Any <#> in the example should be removed when copying it. You can use the _cat APIs to get a human readable, tabular output for various reasons. GET /_cat/health?v <1> The ?v is optional, but it implies that you want "verbose" output. _...
Free version of SSH protocol implementation, OpenSSH is available in all the Linux distributions. It consists of the server and client packages. Installation On Debian-based Linux, you can install openssh using # apt-get install openssh-server openssh-client On RHEL/CentOS you need to use yum:...
One can select rows and columns of a dataframe using boolean arrays. import pandas as pd import numpy as np np.random.seed(5) df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"), index = ["R" + str(i) for i in range(5)]) print (...
All files are in folder files. First create list of DataFrames and then concat them: import pandas as pd import glob #a.csv #a,b #1,2 #5,8 #b.csv #a,b #9,6 #6,4 #c.csv #a,b #4,3 #7,0 files = glob.glob('files/*.csv') dfs = [pd.read_csv(fp) for fp in files] #duplicated ind...
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, ...
import pandas as pd import numpy as np np.random.seed(0) tuples = list(zip(*[['bar', 'bar', 'foo', 'foo', 'qux', 'qux'], ['one', 'two', 'one', 'two','one', 'two']])) idx = pd.MultiIndex.from_tuples(tuples, names=['first', 'second']) df = pd.DataFrame(np.random.randn(6, ...
use std::error::Error; use std::fmt; use std::convert::From; use std::io::Error as IoError; use std::str::Utf8Error; #[derive(Debug)] // Allow the use of "{:?}" format specifier enum CustomError { Io(IoError), Utf8(Utf8Error), Other, } // Allow the use of "{...
data.table offers a wide range of possibilities to reshape your data both efficiently and easily For instance, while reshaping from long to wide you can both pass several variables into the value.var and into the fun.aggregate parameters at the same time library(data.table) #v>=1.9.6 DT <- ...
The ** operator works similarly to the * operator but it applies to keyword parameters. def options(required_key:, optional_key: nil, **other_options) other_options end options(required_key: 'Done!', foo: 'Foo!', bar: 'Bar!') #> { :foo => "Foo!", :bar => "Bar!" ...
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 ...
struct Struct<'a> { x: &'a u32, } This specifies that any given instance of Struct has lifetime 'a, and the &u32 stored in x must have a lifetime of at least 'a.
impl<'a> Type<'a> { fn my_function(&self) -> &'a u32 { self.x } } This specifies that Type has lifetime 'a, and that the reference returned by my_function() may no longer be valid after 'a ends because the Type no longer exists to hold self.x.
.Net 4.0 type Lazy guarantees thread-safe object initialization, so this type could be used to make Singletons. public class LazySingleton { private static readonly Lazy<LazySingleton> _instance = new Lazy<LazySingleton>(() => new LazySingleton()); public stati...
The * operator can be used to unpack variables and arrays so that they can be passed as individual arguments to a method. This can be used to wrap a single object in an Array if it is not already: def wrap_in_array(value) [*value] end wrap_in_array(1) #> [1] wrap_in_array([1, 2, 3]) ...
Instead of requesting an ILoggerFactory and creating an instance of ILogger explicitly, you can request an ILogger (where T is the class requesting the logger). public class TodoController : Controller { private readonly ILogger _logger; public TodoController(ILogger<TodoController...
Using iris dataset: import sklearn.datasets iris_dataset = sklearn.datasets.load_iris() X, y = iris_dataset['data'], iris_dataset['target'] Data is split into train and test sets. To do this we use the train_test_split utility function to split both X and y (data and target vectors) randomly w...
Finding patterns in data often proceeds in a chain of data-processing steps, e.g., feature selection, normalization, and classification. In sklearn, a pipeline of stages is used for this. For example, the following code shows a pipeline consisting of two stages. The first scales the features, and t...

Page 255 of 1336