In R I can have a data.frame or a list with several arguments, and I can operate on them using the with
function. For example:
d <- data.frame(x = 1:3, y = 2:4, z = 3:5)
# I can use:
d$x+d$y*d$z-5
# Or, more simply, I can use:
with(d, x+y*z-5)
# [1] 2 9 18
In pandas DataFrame I can use:
d = {'x': [1, 2, 3], 'y': [2, 3, 4], 'z': [3, 4, 5]}
df = pd.DataFrame(data=d)
df.x+df.y*df.z-5
# 0 2
# 1 9
# 2 18
# dtype: int64
But is there a way to do some "with" like statement?
Pandas for Python and Dplyr for R are the two most popular libraries for working with tabular/structured data for many Data Scientists.
The Apply Function in Python The pandas package for Python also has a function called apply, which is equivalent to its R counterpart; the following code illustrates how to use it.
The PANDA R package (Preferential Attachment based common Neighbor Distribution derived Associations) was designed to perform the following tasks: (1) identify significantly functionally associated protein pairs, (2) predict GO and KEGG terms for proteins, (3) make a cluster of proteins based on the significant protein ...
Dplython. Package dplython is dplyr for Python users. It provide infinite functionality for data preprocessing.
One idea is use DataFrame.eval
if need processing some columns names some simple arithmetic operations:
print (df.x+df.y*df.z-5)
0 2
1 9
2 18
dtype: int64
print (df.eval('x+y*z-5'))
0 2
1 9
2 18
dtype: int64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With