0

I have this Pandas table:

       Type    A    B    C   AB   AC   BC  ABC  
0  mean(+1)  NaN  NaN  NaN  NaN  NaN  NaN  NaN   
1  mean(-1)  NaN  NaN  NaN  NaN  NaN  NaN  NaN                 
2     slope  NaN  NaN  NaN  NaN  NaN  NaN  NaN  

considering "mean(+1)" as another column with its header name as "Type" in a different column. and "ABC" as a column header, so how do I write to the position in the coordinates [mean(+1), ABC]?

Marcelo
  • 45
  • 1
  • 8
  • 4
    Possible duplicate of [Set value for particular cell in pandas DataFrame](https://stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe) – Kris Jan 25 '18 at 16:49

1 Answers1

0

You can use the Index for axis 0 and a boolean mask to figure this out:

ax0 = df.index[df['Type'] == 'mean(+1)']
df.loc[ax0, 'ABC']

returns the NaN corresponding with index 0 and column 'ABC':

0   NaN
Name: ABC, dtype: float64
Alex
  • 15,252
  • 6
  • 48
  • 75
  • Alex, thanks, you have me the directions! I wrote: df.at[df["Type"]=="mean(+1)","ABC"] = 1.0 Thanks! – Marcelo Jan 25 '18 at 17:40
  • For performance, I recommend using `pd.DataFrame.iat`, which requires integer locations. This may involve a small amount of extra code to map to integer locations. – jpp Jan 25 '18 at 17:45
  • You could just use ``df.loc[df.Type == 'mean(+1)', 'ABC']``. – prooffreader Jan 25 '18 at 17:57