Is there a general efficient way to assign values ββto a subset of a DataFrame in pandas? I have hundreds of rows and columns that I can access directly, but I was not able to figure out how to edit their values ββwithout repeating through each pair of rows, col. For instance:
In [1]: import pandas, numpy In [2]: array = numpy.arange(30).reshape(3,10) In [3]: df = pandas.DataFrame(array, index=list("ABC")) In [4]: df Out[4]: 0 1 2 3 4 5 6 7 8 9 A 0 1 2 3 4 5 6 7 8 9 B 10 11 12 13 14 15 16 17 18 19 C 20 21 22 23 24 25 26 27 28 29 In [5]: rows = ['A','C'] In [6]: columns = [1,4,7] In [7]: df[columns].ix[rows] Out[7]: 1 4 7 A 1 4 7 C 21 24 27 In [8]: df[columns].ix[rows] = 900 In [9]: df Out[9]: 0 1 2 3 4 5 6 7 8 9 A 0 1 2 3 4 5 6 7 8 9 B 10 11 12 13 14 15 16 17 18 19 C 20 21 22 23 24 25 26 27 28 29
I believe that what happens here is that I get a copy, not a view, that is, I can not assign the original DataFrame. That's my problem? What is the most efficient way to edit these rows x columns (preferably at a pace since a DataFrame can take up a lot of memory)?
Also, what if I want to replace these values ββwith a properly formed DataFrame?
source share