Storing data in a data frame
Question: New to python I'm struggling with a way to combine operation on my raw data
and a way to store them in a data frame and then using it again with pandas
and R.

some example of my code:

    
    
    if 'Subject' in f:
         for i in range (len(time)):
              (...)
                        if  Description[j] == 'response':  
                            RT.append(time[j] - time_stim)
                            motor_time.append(time[j] - time_response)                
                            break
    

My raw data is a .txt file example below:

    
    
    Type,Description,Time,Channel 
    Categorie,PC,153,1,All 
    Stimulus,S11,1510,1,All 
    Stimulus,S202,3175,1,All 
    Stimulus,EMG_Onset,3978,1,EMGL 
    Stimulus,response,4226,1,All 
    Categorie,CC,5785,1,All 
    Stimulus,S11,7141,1,All 
    Stimulus,S202,8807,1,All 
    Stimulus,EMG_Onset,9549,1,EMGL
    Stimulus,EMG_Onset,9965,1,EMGL 
    Stimulus,response,10249,1,All
    

In this example, I want to store RT or motor_time which I got from this piece
of code in a yet non-existent data frame to use it first with python then with
R. This data frame would have to store all parameters for all my experimental
conditions and subject

In this case, all results are stored in numeric np.array and I don't know how
to use them with specific R code I created before.

Thanks.


Answer: I should first say, that I do not see any reason for you to mix python and R.

If you have your analysis already in R, you can directly read your TXT file
into R data frame

    
    
    df = read.csv("myfile.txt")
    head(df)  # to display the first few rows of your data frame
    

Your 1st, 2nd and 5th columns will be converted to factors (you can change it
if you desired).

If you want python, you can read your file into pandas DataFrame.

    
    
    import pandas as pd
    df = pd.read_csv("myfile.txt")
    df.head()  # to display the first few rows of your data frame
    

If this is not a solution for your question, please indicate what do you want
beyond this?

There is a [rpy](http://rpy.sourceforge.net/) package which allows you to use
R code in python. It requires extra python programming code anyway.

As to importing pandas data frame into R: I would save it into CSV file or
other format (save as "save on hard disk") and then open in R. But CSV file is
what you initially get, so no point for you.

