QST: why changing dataframe values impacts the array that the dataframe was created from?
See original GitHub issue-
I have searched the [pandas] tag on StackOverflow for similar questions.
-
I have asked my usage related question on StackOverflow.
Question about pandas
>>> import numpy as np
>>> import pandas as pd
>>> mat = np.array([[1,2], [2,3]])
>>> mat
array([[1, 2],
[2, 3]])
>>> df = pd.DataFrame(mat)
>>> df.iloc[0,1] = 4
>>> mat
array([[1, 4],
[2, 3]])
Why the value in the original mat
is also changed? I am not sure if this is a bug or Pandas’ way of doing things. I found it to be very confusing.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
python - Will changes in DataFrame.values always modify the ...
It's an implementation detail if a copy is returned (then changing the values would not change the DataFrame) or if values returns a...
Read more >pandas.DataFrame — pandas 0.21.1 documentation
Assign new columns to a DataFrame, returning a new object (a copy) with all the original columns in addition to the new ones....
Read more >12 Useful Pandas Techniques in Python for Data Manipulation
Introduction · Let's get started · #1 – Boolean Indexing in Pandas · #2 – Apply Function in Pandas · #3 – Imputing...
Read more >How to Replace Values in Pandas DataFrame - Data to Fish
(2) Replace multiple values with a new value for an individual DataFrame column: df['column name'] = df['column name'].replace(['1st old ...
Read more >10 Data manipulation with pandas | Python for economists
When the dataframe was created, the GDP value for Germany was therefore assigned as NaN . 10.1.2.5 Creation of Dataframes from a Two-dimensional...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
closing - democracy seems to have identified this as a non-issue, but rather an educational question for which an answer was given
@Varun270 the relevant code will be in
pandas.core.frame
orpandas.core.generic
. However, it seems to me there is no issue to be resolved here.