Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Vector syntax in Python / Pandas

Tags:

python

pandas

r

I've created the following code in R.

data=c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")
  terms<- paste(data, collapse='+')

and this gives;

"Sepal.Length+Sepal.Width+Petal.Length+Petal.Width"

Is there a way of doing something similar in Python / Pandas?

like image 606
fred.schwartz Avatar asked Jan 30 '26 15:01

fred.schwartz


1 Answers

use join:

d = ["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"]
x = '+'.join(d)
print(x)

output:

Sepal.Length+Sepal.Width+Petal.Length+Petal.Width
like image 185
Nihal Avatar answered Feb 01 '26 08:02

Nihal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!