Q:

Assigning a value to a single row for a Pandas DataFrame column

I am trying to reassign a value in a single row of a column in a Pandas DataFrame. 
import pandas as pd
import numpy as np

Here's the DataFrame:
test_df = pd. DataFrame({'range_total' : [3000,3000,3000,3000,3000,3000,0,2000,2000,1000,1000,1000,1000,1000,1000],
    'high_boundary' : [6,6,6,6,6,6,7,9,9,15,15,15,15,15,15],
    'dist_num' : [1197, 142, 142, 1197, 159, 159, 0, 1000, 1000, 398, 50, 50, 398, 50, 50],
    'round_num_sum' : [2996, 2996, 2996, 2996, 2996, 2996, 0, 2000, 2000, 996, 996, 996, 996, 996, 996]})

In my code I subset the DataFrame for each value of high_boundary and find the index(es) of the test_df corresponding to the greatest value of dist_num (picking the first if tied).  For this example, I set the index to:
sub_idx = 0 

I can access the value using this (and other similar versions) code:
test_df.ix[(test_df.high_boundary == 6), "dist_num"][sub_idx]

that returns:
1197

But assigning a new value fails:
test_df.ix[(test_df.high_boundary == 6), "dist_num"][sub_idx] = 42
test_df.ix[(test_df.high_boundary == 6), "dist_num"][sub_idx]

which still returns:
1197 

But:
test_df.ix[(test_df.high_boundary == 6), "dist_num"] = 42
test_df.ix[(test_df.high_boundary == 6), "dist_num"]

returns:
0    42
1    42 
2    42
3    42
4    42
5    42
Name: dist_num, dtype: int64

I appreciate any help.  This is my first post, because I've always found what I've needed on SO until now.  I'm using version 0.14.0. 

A:

Sometimes you can get copy of (part of) original dataframe test_df. 
Especially if you select elements using  [...][...]
So you changed one value in copy, not in oryginal test_df
Try for example this:
test_df["dist_num"].ix(test_df.high_boundary == 6)[sub_idx] = 0

and you should get expected result.