Skip to content
Advertisement

python jupyter Same condition tested in an if statement behave differently

Have a Jupyter Lab notebook which at a certain point compares two dataframes. df_lastweek is an extraction of only last week’s data while the df_lastmonth is the extraction of the last 30 days. The two dataframes are different the latter having more rows than the former.

The following if comparing the two different dataframes does not trigger:

JavaScript

while the next cell uses the SAME statement and does trigger as expected: if not df_lastweek.equals(df_lastmonth): regplot_of_df(df_lastmonth, 2000) and regularly call the regplot_of_df function plotting the data as expected.

Tried inverting the two cells but the describe statement never gets called.

No clue as to what I’m missing. Follows some more data about the two dataframes and also if anyone cares to check all of the notebook you may find it here: , where the “offending” cells are the very last three: [https://github.com/rjalexa/blood-pressure/blob/master/bplogs_analyze.ipynb][1]

JavaScript

Advertisement

Answer

The if works, it just doesn’t show the result as it’s not the last expression in the cell. You need do use display:

JavaScript

Alternatively, you may set InteractiveShell.ast_node_interactivity to 'all'.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement