Skip to content

Instantly share code, notes, and snippets.

View MarcinMoskala's full-sized avatar

Marcin Moskała MarcinMoskala

View GitHub Profile
def add_day_month_year(df):
dates = df["Date"].map(lambda x: x[:10])
df["day_of_month"] = dates.map(lambda x: x.split("/")[1])
df["month"] = dates.map(lambda x: x.split("/")[0])
df["year"] = dates.map(lambda x: x.split("/")[2])
df["date"] = dates
return df
from pandas import read_csv
def add_day_month_year(df):
dates = df["Date"].map(lambda x: x[:10])
df["day_of_month"] = dates.map(lambda x: x.split("/")[1])
df["month"] = dates.map(lambda x: x.split("/")[0])
df["year"] = dates.map(lambda x: x.split("/")[2])
df["date"] = dates
return df
from pandas import read_csv
data class Student(
val id: Int,
val name: String,
val surname: String
)
class StudentsFactory {
var nextId = 0
fun next(name: String, surname: String) =
Student(nextId++, name, surname)
// Constructor:
val f: ()->Tree = ::Tree
// Fake constructor:
val f: ()->Tree = ::Tree
// Invoke in companion object:
val f: ()->Tree = Tree.Companion::invoke
// Constructor:
val f: ()->Tree = ::Tree
// Fake constructor:
val f: ()->Tree = ::Tree
// Invoke in companion object:
val f: ()->Tree = Tree.Companion::invoke
Tree.invoke(10) { "$it" }
class Tree<T> {
companion object {
operator fun <T> invoke(size: Int, generator: (Int)->T): Tree<T>{
//…
}
}
}
// Usage
Tree(10) { "$it" }
public inline fun <T> List(
size: Int,
init: (index: Int) -> T
): List<T> = MutableList(size, init)
public inline fun <T> MutableList(
size: Int,
init: (index: Int) -> T
): MutableList<T> {
val list = ArrayList<T>(size)
List(4) { "User$it" } // [User0, User1, User2, User3]
val reference: ()->A = ::A