Given a DataFrame with MultiIndex columns
# build an example DataFrame
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']], labels=[[1,1,0,],[1,0,1,]])
df = pd.DataFrame(np.random.randn(2,3), columns=midx)
In [2]: df
Out[2]:
one zero
y x ...
Start with a standard DataFrame
df = pd.DataFrame(np.random.randn(2,3), columns=['a','b','c'])
In [91]: df
Out[91]:
a b c
0 -0.911752 -1.405419 -0.978419
1 0.603888 -1.187064 -0.035883
Now to change to MultiIndex, create a MultiIndex object and assign it to df....
Members of objects or classes can be accessed using the object operator (->) and the class operator (::).
class MyClass {
public $a = 1;
public static $b = 2;
const C = 3;
public function d() { return 4; }
public static function e() { return 5; }
}
$object = new MyCl...
Creating a temporal table with a default history table is a convenient option when you want to control naming and still rely on system to create history table with default configuration. In the example below, a new system-versioned memory-optimized temporal table linked to a new disk-based history t...
As the characters/digits can be anywhere within the string, we require lookaheads. Lookaheads are of zero width meaning they do not consume any string. In simple words the position of checking resets to the original position after each condition of lookahead is met.
Assumption :- Considering non-wo...
This can be done with a bit of modification in the above regex
^(?=.{10,}$)(?=(?:.*?[A-Z]){2})(?=.*?[a-z])(?=(?:.*?[0-9]){2}).*$
or
^(?=.{10,}$)(?=(?:.*[A-Z]){2})(?=.*[a-z])(?=(?:.*[0-9]){2}).*
Let's see how a simple regex ^(?=(?:.*?[A-Z]){2}) works on string abcAdefD
Image Credit :- ht...
SQL Server 2008 R2
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
This isolation level is the 2nd most permissive. It prevents dirty reads. The behavior of READ COMMITTED depends on the setting of the READ_COMMITTED_SNAPSHOT:
If set to OFF (the default setting) the transaction uses shared l...
After installing a Java SDK, it is advisable to check that it is ready to use. You can do this by running these two commands, using your normal user account:
$ java -version
$ javac -version
These commands print out the version information for the JRE and JDK (respectively) that are on your sh...
// 3. Covariant smart pointer result (automated cleanup).
#include <memory>
using std::unique_ptr;
template< class Type >
auto up( Type* p ) { return unique_ptr<Type>( p ); }
class Top
{
private:
virtual Top* virtual_clone() const = 0;
public:
unique_ptr&l...
Coments
"Comments are enclosed in double quotes. BEWARE: This is NOT a string!"
"They can span
multiple lines."
Strings
'Strings are enclosed in sigle quotes.'
'Single quotes are escaped with a single quote, like this: ''.'
'''' "<--This string contains one sin...
The only major differences between this and a regular TCP connection are the private Key and the public certificate that you’ll have to set into an option object.
How to Create a Key and Certificate
The first step in this security process is the creation of a private Key. And what is this private ...
post-receive hooks can be used to automatically forward incoming pushes to another repository.
$ cat .git/hooks/post-receive
#!/bin/bash
IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
echo "$remote_ref" | egrep '^refs\/heads\/[A-Z]+-[0-9]+$' >/dev/null &am...
Class Car
...
' Parameterless Constructor
Public Sub Class_Initialize()
distances_ = Array(0)
End Sub
' Default initialization method that can be invoked without
' explicitly using the method name.
Public Default Function Init(wheels)
wheels_ = ...
This is how the author sets their personal PS1 variable:
gitPS1(){
gitps1=$(git branch 2>/dev/null | grep '*')
gitps1="${gitps1:+ (${gitps1/#\* /})}"
echo "$gitps1"
}
#Please use the below function if you are a mac user
gitPS1ForMac(){
git branch 2> ...
The ROLLUP operator is useful in generating reports that contain subtotals and totals.
CUBE generates a result set that shows aggregates for all combinations of values in the selected columns.
ROLLUP generates a result set that shows aggregates for a hierarchy of values in the selected col...
Sometimes you might have branches lying around that have already had their changes merged into master. This finds all branches that are not master that have no unique commits as compared to master. This is very useful for finding branches that were not deleted after the PR was merged into master.
...
Multiple comparison operators used together are chained, as if connected via the && operator. This can be useful for readable and mathematically concise comparison chains, such as
# same as 0 < i && i <= length(A)
isinbounds(A, i) = 0 < i ≤ length(A)
# same as Set...
Immediately continue reading on invalid input or break on user request or end-of-file:
#include <stdlib.h> /* for EXIT_xxx macros */
#include <stdio.h> /* for printf() and getchar() */
#include <ctype.h> /* for isdigit() */
void flush_input_stream(FILE * fp);
int main(v...
Sometimes, programmers who are new to Java make the mistake of defining a class with a name that is the same as a widely used class. For example:
package com.example;
/**
* My string utilities
*/
public class String {
....
}
Then they wonder why they get unexpected errors. For ex...
element.style only reads CSS properties set inline, as an element attribute. However, styles are often set in an external stylesheet. The actual style of an element can be accessed with window.getComputedStyle(element). This function returns an object containing the actual computed value of all the ...