Python | Difference between Pandas.copy() and copying through variables Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report Pandas .copy() method is used to create a copy of a Pandas object. Variables are also used to generate copy of an object but variables are just pointer to an object and any change in new data will also change the previous data. The following examples will show the difference between copying through variables and Pandas.copy() method. Example #1: Copying through variables In this example, a sample Pandas series is made and copied in a new variable. After that, some changes are made in the new data and compared with the old data. Python3 1== # importing pandas module import pandas as pd # creating sample series data = pd.Series(['a', 'b', 'c', 'd']) # creating copy of series new = data # assigning new values new[1]='Changed value' # printing data print(new) print(data) Output: As shown in the output image, the changes made in new data are also reflected in the old data since the new variable was just a pointer to old one. Example #2: Using Pandas.copy() method In this example, pandas.copy() method is used to copy a data and some changes are made in the new data. The changes are then compared to old data. Python3 1== # importing pandas module import pandas as pd # creating sample series data = pd.Series(['a', 'b', 'c', 'd']) # creating copy of series new = data.copy() # assigning new values new[1]='Changed value' # printing data print(new) print(data) Output: As shown in the output image, the changes in new data are independent and didn't change anything in old one. Comment More infoAdvertise with us Next Article Python | Difference between Pandas.copy() and copying through variables K Kartikaybhutani Follow Improve Article Tags : Misc Python Python-pandas Python pandas-series Python pandas-series-methods +1 More Practice Tags : Miscpython Similar Reads Difference between Pandas and PostgreSQL Pandas: Python supports an in-built library Pandas, to perform data analysis and manipulation is a fast and efficient way. Pandas library handles data available in uni-dimensional arrays, called series, and multi-dimensional arrays called data frames. It provides a large variety of functions and uti 4 min read Difference Between Shallow copy VS Deep copy in Pandas Dataframes The pandas library has mainly two data structures DataFrames and Series. These data structures are internally represented with index arrays, which label the data, and data arrays, which contain the actual data. Now, when we try to copy these data structures (DataFrames and Series) we essentially cop 4 min read Difference Between x = x + y and x += y in Python We often use x += y instead of x = x + y. So, are they same or different? Let's Find it here. Example 1: Python3 x = [1, 2] another_x = x y = [3] x += y print(x) print(another_x) Output: [1, 2, 3] [1, 2, 3] Example 2: Python3 x = [1, 2] another_x = x y = [3] x = x + y print(x) print(another_x) Outpu 2 min read Difference between Variable and get_variable in TensorFlow In this article, we will try to understand the difference between the Variable() and get_variable() function available in the TensorFlow Framework. Variable() Method in TensorFlow A variable maintains a shared, persistent state manipulated by a program. If one uses this function then it will create 1 min read Adding New Variable to Pandas DataFrame In this article let's learn how to add a new variable to pandas DataFrame using the assign() function and square brackets. Pandas is a Python package that offers various data structures and operations for manipulating numerical data and time series. It is mainly popular for importing and analyzing d 3 min read Like