Python panda reset_index(inplace=true) prints only 1 out of 2 print() lines


#1

i’m trying to understand why for script like below it would only print 1 line

df3 = df2.reset_index(inplace=True,drop=True)
print(df2)
print(df3)

** if set print(df2) and again print(df2) it will get two prints
*** if set inplace=False - i’d get two print()

the lesson is here
https://www.codecademy.com/courses/dspath-intro-pandas/lessons/pandas-i/exercises/reset-index


#2

Hello @vovab,

You getting the same print() result because you are modifying the dataframe df2 inplace, that means both df3 and df2 are the same and probably the python enviroment of Codecademy is avoiding repeated print results.

Remember to focus on the chapter topic which is notice how the keyword arguments of the .reset_index method affects the original dataframe df2.


#3

Hi

I mentioned I can still achieve 2 repeating lines printed, so it must be something else specific to this method doing this.

Afraid your response doesn’t clarify it.

Thx


#4

Hi @vovab

Some of the exercises provide a text output window directly underneath the code editing window, however, this one does not provide one there. If you execute your code in an exercise that does provide such an output window, you would see output from both of your print statements.

The exercise Inspect a DataFrame is an example of one that does provide an output window, which is visible under the Run button.