Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:43:38+00:00 2026-06-07T23:43:38+00:00

I am having trouble converting a pandas DataFrame in Python to an R object,

  • 0

I am having trouble converting a pandas DataFrame in Python to an R object, for future use in R using rpy2.

The new pandas release 0.8.0 (released a few weeks ago) has a function to convert pandas DataFrames to R DataFrames. The problem is in converting the first column of my pandas DataFrame, which consists of python datetime objects (successively, in a time series). The conversion into an R dataframe returns an StrVector of the dates and times, rather than a vector of R datetime-type objects which I believe are called “POSIXct” objects.

I know the command to convert a string of the type returned to a POSIXct, using the command “as.POSIXct(‘yyyy-mm-dd hh:mm:ss’)”. Unfortunately I have not been able to figure out the way to convert all these strings in the StrVector to POSIXct using python and rpy2. The dates need to be in the POSIXct format to be used with the TTR library in R. Below is the relevant python code:

import pandas
from pandas import *
import pandas.rpy.common as com
import rpy2.robjects as robjects
r = robjects.r
r.library('TTR')        #library contains the function ADX, to be used later

dataframe = read_csv('file_name', parse_dates = [0], names  = ['Date','Col1','Col2','Col3']     #command makes 1st column into datetime.datetime object
r_dataframe = com.convert_to_r_dataframe(dataframe)

ADX = r['ADX']          #creating a name for an R function in python
adx = ADX(r_dataframe)    #will not work because the dates in r_dataframe are in a StrVector

Further I do not believe that the StrVector can be iterated through to convert each object to a POSIXct object individually, due to the definition of a StrVector. Maybe there is a way to cast a StrVector to a generic one?

Any help/insight into this matter is greatly appreciated. I am a novice programmer and have been working on this for a couple hours now to no avail.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:43:39+00:00Added an answer on June 7, 2026 at 11:43 pm

    The reason your ADX call fails is because it expects an xts or matrix-like object with 3 columns: High, Low, Close. Your object contains 4 columns. Drop the date column before passing r_dataframe to ADX and everything should work. You can then add the datetime column back to the ADX output.

    Or, if you can set the row.names attribute of your R data.frame to the values of the Date column and then remove the Date column, you can convert your R data.frame to an xts object by calling as.xts(r.data.frame). Then you can pass that to ADX and convert the result back to a pandas DataFrame.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new to python and I'm having trouble converting a script to a more effective
I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting
I am having trouble with converting time, when I use the date() function on
I am writing a small forensics python app and I am having trouble converting
I am having trouble converting a CFDataRef into NSData whilst using ARC . I
Am new to Groovy and am having trouble converting an array to JSON. The
I'm having trouble converting a JPA query to the use the Criteria API I
I'm having trouble converting a Perl regex to Python. The text I'm trying to
I'm having trouble converting DMS to DD in javascript using regular expressions. I took
I'm having trouble converting objects into JSONObject (org.json.JSONObject) in java. I have an object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.