py-datatable

What is the Python equivalent to R data.table column creation?

What is the Python equivalent to R data.table column creation? Question: I’m in the process of converting my R scripts to python. Is there a similar process in creating new columns that r data.table does in the J step? Below is my example code in R: dat[,Returned_on_time:= ifelse(Contract_End_Date==Estimated_In_Date,’Yes’,’No’)] Thanks Asked By: Zachqwerty || Source Answers: …

Total answers: 2

Remove rows which have na values

Remove rows which have na values Question: I have the following datatable in python:- # A B B_lag_1 B_lag_2 B_lag_3 B_lag_4 #0 0 −0.342855 NA NA NA NA #1 0 0.0706784 −0.342855 NA NA NA #2 0 0.0470259 0.0706784 −0.342855 NA NA #3 0 −0.0522357 0.0470259 0.0706784 −0.342855 NA #4 0 −0.610938 −0.0522357 0.0470259 0.0706784 …

Total answers: 2

switch column locations in python datatable

switch column locations in python datatable Question: What is the most efficient way to switch the locations of two columns in python datatable? I wrote the below function that does what I want, but this may not be the best way, especially if my actual table is big. Is it possible to do this in …

Total answers: 2

Any simpler way to assign multiple columns in Python like R data.table :=

Any simpler way to assign multiple columns in Python like R data.table := Question: I’m wondering if there’s any simpler way to assign multiple columns in Python, just like the := in R data.table. For example, in Python I would have to write like this: df[‘Col_A’] = df.A/df.B df[‘Col_B’] = df.C/df.D df[‘Col_C’] = df.E/df.F * …

Total answers: 3

create row number by group, using python datatable

create row number by group, using python datatable Question: If I have a python datatable like this: from datatable import f, dt data = dt.Frame(grp=["a","a","b","b","b","b","c"], value=[2,3,1,2,5,9,2]) how do I create an new column that has the row number, by group?. That is, what is the equivalent of R data.table‘s data[, id:=1:.N, by=.(grp)] This works, but …

Total answers: 2

Pydatatable enumerate rows within each group

Pydatatable enumerate rows within each group Question: Given the following datatable DT = dt.Frame({‘A’:[‘A’,’A’,’A’,’B’,’B’,’B’], ‘B’:[‘a’,’a’,’b’,’a’,’a’,’a’], }) I’d like to create column ‘C’, which numbers the rows within each group in columns A and B like this: A B C 0 A a 1 1 A a 2 2 A b 1 3 B a 1 …

Total answers: 1

How to find unique values by group in datatable Frame

How to find unique values by group in datatable Frame Question: I have created a datatable frame as follows, DT_EX = dt.Frame({‘cid’:[1,2,1,2,3,2,4,2,4,5], ‘cust_life_cycle’:[‘Lead’,’Active’,’Lead’,’Active’,’Inactive’,’Lead’,’Active’,’Lead’,’Inactive’,’Lead’]}) Here I have three unique customer life cycles and each of these counts are found as DT_EX[:, count(), by(f.cust_life_cycle)] Along with it, I have five customer IDs and these counts are as …

Total answers: 3