Pandas - apply function over one column and return a new column
<p>I have a function <code>findFullPath</code> that takes a string of a file and finds the full path of that file using a list of the full paths. For example;</p>

<pre><code>    &gt;&gt;&gt; i = 4000
    &gt;&gt;&gt; serisuid = candidates.iloc[i].seriesuid
    &gt;&gt;&gt; fullPath = findFullPath(serisuid,fullPaths)
    &gt;&gt;&gt; print(serisuid)
    &gt;&gt;&gt; print(fullPath)

    1.3.6.1.4.1.14519.5.2.1.6279.6001.100684836163890911914061745866
    /home/msmith/luna16/subset1/1.3.6.1.4.1.14519.5.2.1.6279.6001.100684836163890911914061745866.raw
</code></pre>

<p>I am trying to apply this function to the full column candidates["seriesuid"] and to return a new column with the full paths using something like below but so far it is unsuccessful;</p>

<pre><code>&gt;&gt;&gt; candidates["seriesuidFullPaths"] = candidates[["seriesuid"]].apply(findFullPath,args=(fullPaths,),axis=1)
</code></pre>

<p>[EDIT]</p>

<p>Sorry to be a bit ambiguous. So my function is </p>

<pre><code>def findFullPath(seriesuid,fullPaths):
    fullPath = [s.replace(".mhd",".raw") for s in fullPaths if serisuid in s][0]
    return fullPath
</code></pre>

<p>which works perfectly in the case by case code I gave at the top but yields the incorrect full file paths when I apply it over the series. Moreover I get a copy error;</p>

<pre><code>A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
</code></pre>

<p>However I thought that I was editing the actual data frame so I am a bit confused.</p>

<p>[EXAMPLE]</p>

<pre><code>&gt;&gt;&gt; candidates.head()

                                                          seriesuid  coordX  \
0  1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860  -56.08   
1  1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860   53.21   
2  1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860  103.66   
3  1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860  -33.66   
4  1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860  -32.25   

   coordY  coordZ  class  
0  -67.85 -311.92      0  
1 -244.41 -245.17      0  
2 -121.80 -286.62      0  
3  -72.75 -308.41      0  
4  -85.36 -362.51      0  
</code></pre>

<p>I just updated fullPaths to include just the <code>.raw</code> files.</p>

<pre><code>&gt;&gt;&gt; fullPaths = [path for path in fullPaths if ".raw" in path]
&gt;&gt;&gt; fullPaths[:5] 
['/home/msmith/luna16/subset4/1.3.6.1.4.1.14519.5.2.1.6279.6001.142154819868944114554521645782.raw',
     '/home/msmith/luna16/subset4/1.3.6.1.4.1.14519.5.2.1.6279.6001.211071908915618528829547301883.raw',
     '/home/msmith/luna16/subset4/1.3.6.1.4.1.14519.5.2.1.6279.6001.390009458146468860187238398197.raw',
     '/home/msmith/luna16/subset4/1.3.6.1.4.1.14519.5.2.1.6279.6001.463214953282361219537913355115.raw',
     '/home/msmith/luna16/subset4/1.3.6.1.4.1.14519.5.2.1.6279.6001.252358625003143649770119512644.raw']
</code></pre>

<p>I want to replace each seriesuid in candidates with the relevant .raw file path. Hope this clears it up.</p>