On 2012-02-24 09:55, Luca Beltrame wrote:
Hello,

in an effort to create a conversion between pandas objects[1] and R's
data.frames,

This would be handy. A common interface ("protocol" in the Python lingo) would allow duck typing.

  I'm trying to add columns to an empty DataFrame.

Python code:

from rpy2.robjects.packages import importr

base = importr("base")
my_row_names =
empty = base.data_frame(row_names=[item for item in range(1000)] )

Problems arise when I try to add a column through the rx2 accessor:

empty.rx2["New"] = [str(item) for item in range(len(empty.rownames))]

RRuntimeError: Error in `[[<-.data.frame`(list(), "New", list("0", "1", "2",
"3", "4",  :   argument "value" is missing, with no default

Anything I'm doing wrong?

Not necessarily; I think that you are reaching less "battle-tested" corners of rpy2 (may be missing unit tests here and this went unnoticed).
I am intrigued by the line:

empty = base.data_frame(row_names=[item for item in range(1000)] )


Wouldn't a simpler alternative be

empty = base.data_frame(row_names = range(1000))

?... and may be specifying the vector type be needed

empty = base.data_frame(row_names = IntVector(range(1000)))

?

  Or is there a more efficient way?

Appending to R vector is generally not the most efficient.
Try using R's cbind() (column-bind); is not more efficient but it states more clearly what is happening.


  (For reference,
I'm trying to *avoid* creating taggedlists and so on because they involve
intermediates, and with large objects that would mean performance issues).

[1]http://pandas.pydata.org




------------------------------------------------------------------------------
Virtualization&  Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/


_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to