Tutorial by Examples: c

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. _...
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.
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...
Different operations with data are done using special classes. Most of the classes belong to one of the following groups: classification algorithms (derived from sklearn.base.ClassifierMixin) to solve classification problems regression algorithms (derived from sklearn.base.RegressorMixin) to so...
A Service is a component which runs in the background (on the UI thread) without direct interaction with the user. An unbound Service is just started, and is not bound to the lifecycle of any Activity. To start a Service you can do as shown in the example below: // This Intent will be used to star...
await operator and async keyword come together: The asynchronous method in which await is used must be modified by the async keyword. The opposite is not always true: you can mark a method as async without using await in its body. What await actually does is to suspend execution of the code ...
1) BASIC SIMPLE WAY Database-driven applications often need data pre-seeded into the system for testing and demo purposes. To make such data, first create the seeder class ProductTableSeeder use Faker\Factory as Faker; use App\Product; class ProductTableSeeder extends DatabaseSeeder { pub...

Page 158 of 826