Tutorial by Examples: c

pd.read_excel('path_to_file.xls', sheetname='Sheet1') There are many parsing options for read_excel (similar to the options in read_csv. pd.read_excel('path_to_file.xls', sheetname='Sheet1', header=[0, 1, 2], skiprows=3, index_col=0) # etc.
%{username: username} = %{username: "John Doe", id: 1} # username == "John Doe" %{username: username, id: 2} = %{username: "John Doe", id: 1} ** (MatchError) no match of right hand side value: %{id: 1, username: "John Doe"}
Unlike regular functions, lambda expressions can capture their environments. Such lambdas are called closures. // variable definition outside the lambda expression... let lucky_number: usize = 663; // but the our function can access it anyway, thanks to the closures let print_lucky_number = ...
// lambda expressions can have explicitly annotated return types let floor_func = |x: f64| -> i64 { x.floor() as i64 };
Returning lambdas (or closures) from functions can be tricky because they implement traits and thus their exact size is rarely known. // Box in the return type moves the function from the stack to the heap fn curried_adder(a: i32) -> Box<Fn(i32) -> i32> { // 'move' applies move se...
State in React components is essential to manage and communicate data in your application. It is represented as a JavaScript object and has component level scope, it can be thought of as the private data of your component. In the example below we are defining some initial state in the constructor f...
If no ordering function is passed, std::sort will order the elements by calling operator< on pairs of elements, which must return a type contextually convertible to bool (or just bool). Basic types (integers, floats, pointers etc) have already build in comparison operators. We can overload this ...
// Include sequence containers #include <vector> #include <deque> #include <list> // Insert sorting algorithm #include <algorithm> class Base { public: // Constructor that set variable to the value of v Base(int v): variable(v) { } i...
C++11 // Include sequence containers #include <vector> #include <deque> #include <list> #include <array> #include <forward_list> // Include sorting algorithm #include <algorithm> class Base { public: // Constructor that set variable to the va...
To add a new unique column email to users, run the following command: rails generate migration AddEmailToUsers email:string:uniq This will create the following migration: class AddEmailToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :email, :string add_index...
BigInteger is in an immutable object, so you need to assign the results of any mathematical operation, to a new BigInteger instance. Addition: 10 + 10 = 20 BigInteger value1 = new BigInteger("10"); BigInteger value2 = new BigInteger("10"); BigInteger sum = value1.add(value...
Model with ForeignKey We will work with these models : from django.db import models class Book(models.Model): name= models.CharField(max_length=50) author = models.ForeignKey(Author) class Author(models.Model): name = models.CharField(max_length=50) Suppose we often (always) access ...
You can access each property that belongs to an object with this loop for (var property in object) { // always check if an object has a property if (object.hasOwnProperty(property)) { // do stuff } } You should include the additional check for hasOwnProperty because an o...
It is undefined behavior to access an index that is out of bounds for an array (or standard library container for that matter, as they are all implemented using a raw array): int array[] = {1, 2, 3, 4, 5}; array[5] = 0; // Undefined behavior It is allowed to have a pointer pointing to the en...
The default property getters and setters can be overridden: @interface TestClass @property NSString *someString; @end @implementation TestClass // override the setter to print a message - (void)setSomeString:(NSString *)newString { NSLog(@"Setting someString to %@", newS...
Assuming a source file of hello_world.v and a top level module of hello_world. The code can be run using various simulators. Most simulators are compiled simulators. They require multiple steps to compile and execute. Generally the First step is to compile the Verilog design. Second step is to ...
The syntax for Java generics bounded wildcards, representing the unknown type by ? is: ? extends T represents an upper bounded wildcard. The unknown type represents a type that must be a subtype of T, or type T itself. ? super T represents a lower bounded wildcard. The unknown type repres...
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) print(df) # Output: # A B # 0 1 4 # 1 2 5 # 2 3 6 Directly assign df['C'] = [7, 8, 9] print(df) # Output: # A B C # 0 1 4 7 # 1 2 5 8 # 2 3 6 9 Add a constant column df['C'] = 1 print(df) # Ou...
For programmers coming from GCC or Clang to Visual Studio, or programmers more comfortable with the command line in general, you can use the Visual C++ compiler from the command line as well as the IDE. If you desire to compile your code from the command line in Visual Studio, you first need to set...
When using labels, both the start and the stop are included in the results. 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)]) ...

Page 138 of 826