How to do arithmetic on imported array in python?
Question: I am new to python and only a student so if this question is extremely trivial
I apologize

I've imported a .csv file and indexed 2 columns using panda using the
following:

    
    
    data_AM = pd.read_csv(name_AM, header = None, names = None, usecols = [2,4])
    

I want to subtract column 4 from column 2 but when I use np.subtract I get an
error telling me that it is a string.

When I attempt to convert the whole column into floats it only converts the
column index header to a float. For example, if I use:

    
    
    x = [float(i) for i in time_AM]
    

where time_AM is column 2, the output is [2.0]

If I do the same thing for column 4, the output is [4.0]

Here is what the output time_AM looks like:

    
    
                 2
    3            0
    4   2.83237624
    5   7.64838266
    6      11.6987
    7     15.60853
    8   19.3890476
    9   25.1548729
    10    30.15414
    11    33.55736
    12  37.2666435
    13    41.67488
    14    45.19324
    15   50.327446
    16  54.7211761
    17  61.7345772
    18    65.96731
    19    72.20469
    20    76.48047
    21    80.90832
    22    84.74452
    

Any advice on how to do arithmetic with this? Basically I am trying to
automate something that would be extremely simple in excel because I'm gonna
have to do it a bunch of times.


Answer: Try this:

    
    
    data_AM.iloc[:, 2].astype('float64').subtract(data_AM.iloc[:,4].astype('float64'))
    

[`.astype('float64')`](http://pandas.pydata.org/pandas-
docs/stable/generated/pandas.Series.astype.html) will convert the datatype of
the column to float. And [`subtract`](http://pandas.pydata.org/pandas-
docs/stable/generated/pandas.Series.subtract.html) is the function you are
looking for. [`.iloc`](http://pandas.pydata.org/pandas-
docs/stable/indexing.html) is an indexer that indexes by position rather than
label.

I understand that the learning curve can be quite steep, Pandas is quite
feature rich and there are lots of things in it. But do take a look at [the
docs](http://pandas.pydata.org/pandas-docs/stable/index.html) for help.

