Tutorial by Examples: c

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...
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...
Imagine a goroutine with a two step process, where the main thread needs to do some work between each step: func main() { ch := make(chan struct{}) go func() { // Wait for main thread's signal to begin step one <-ch // Perform work time.Sle...
Unlike a named class or struct, unnamed classes and structs must be instantiated where they are defined, and cannot have constructors or destructors. struct { int foo; double bar; } foobar; foobar.foo = 5; foobar.bar = 4.0; class { int baz; public: int buzz; ...
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...
This example shows a simple image cropping function that takes an image and cropping coordinates and returns the cropped image. function cropImage(image, croppingCoords) { var cc = croppingCoords; var workCan = document.createElement("canvas"); // create a canvas workCan.wi...
f = fn {:a, :b} -> IO.puts "Tuple {:a, :b}" [] -> IO.puts "Empty list" end f.({:a, :b}) # Tuple {:a, :b} f.([]) # Empty list
When you document your code with @doc, you can supply code examples like so: # myproject/lib/my_module.exs defmodule MyModule do @doc """ Given a number, returns `true` if the number is even, otherwise `false`. ## Example iex> MyModule.even?(2) true ie...
struct FileAttributes { unsigned int ReadOnly: 1; unsigned int Hidden: 1; }; Here, each of these two fields will occupy 1 bit in memory. It is specified by : 1 expression after the variable names. Base type of bit field could be any integral type (8-bit int to 64-bit int). Using u...
C++11 In C++11, compilers are required to implicitly move from a local variable that is being returned. Moreover, most compilers can perform copy elision in many cases and elide the move altogether. As a result of this, returning large objects that can be moved cheaply no longer requires special ha...
Let's have a basic failing program: #include <iostream> void fail() { int *p1; int *p2(NULL); int *p3 = p1; if (p3) { std::cout << *p3 << std::endl; } } int main() { fail(); } Build it (add -g to include debug info): g++ -g -o m...
class API { public: static API& instance(); virtual ~API() {} virtual const char* func1() = 0; virtual void func2() = 0; protected: API() {} API(const API&) = delete; API& operator=(const API&) = delete; }; class WindowsAPI ...
Type check: variable.isInstanceOf[Type] With pattern matching (not so useful in this form): variable match { case _: Type => true case _ => false } Both isInstanceOf and pattern matching are checking only the object's type, not its generic parameter (no type reification), except fo...
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 ...
Bad Example: var location = dbContext.Location .Where(l => l.Location.ID == location_ID) .SingleOrDefault(); return location; Since the above code is simply returning an entity without modifying or adding it, we can avoid tracking cost. Good Ex...
Let's take an example of a function which receives two arguments and returns a value indicating their sum: def two_sum(a, b): return a + b By looking at this code, one can not safely and without doubt indicate the type of the arguments for function two_sum. It works both when supplied with ...

Page 211 of 826