Reputation: 1
I could not quite understand the functionality of copy using reindex. When I tested, copy=False is working only if I am giving exactly same index/columns, in sequence. But this not work if I am changing the sequence of columns/indexes
Statement in Pandas documentation says:
"A new object is produced unless the new index is equivalent to the current one and copy=False.
Actual Code ::
dataframe_obj1 = pd.DataFrame(np.arange(16).reshape(4,4), index = [0,1,2,3], columns = [0,1,2,3])
dataframe_obj1_reindex_copy_False = dat.reindex([3,2,1,0], copy=False)
dataframe_obj1.iloc[0,0] = 500
print("""original dataframe - "dataframe_obj1" after reindexing applied is as below""")
print(dataframe_obj1)
print('\n')
print("""re-indexed dataframe - "dataframe_obj1_reindex_copy_False" is as below""")
print(dataframe_obj1_reindex_copy_False)
Result:
original dataframe - "dataframe_obj1" after reindexing applied is as below
0 1 2 3
0 500 1 2 3
1 4 5 6 7
2 8 9 10 11
3 12 13 14 15
re-indexed dataframe - "dataframe_obj1_reindex_copy_False" is as below
0 1 2 3
3 12 13 14 15
2 8 9 10 11
1 4 5 6 7
0 5 1 2 3
Expecting:
So was expecting value of 500 to get reflected in original data frame as well. But its not happening.
Can someone guide me on this ?
And I guess in case we want to maintain the sequence same and copy=False, how could that be a significant use case as we can achieve it through simple assignment to another variable
Upvotes: 0
Views: 130