When I run a script from the Spyder console using runfile
, source file lines containing expressions (e.g., "HELLO"
) don’t print out to the console. I have to explicitly print, e.g., print("HELLO")
.
Is there a way to output the string representation of a pandas DataFrame using a method? Something like the very last chained method below:
dfShipName[['ShpNm','ShipNamesPrShpNm']]
.drop_duplicates()
.groupby('ShipNamesPrShpNm',as_index=False)['ShipNamesPrShpNm']
.agg(['count'])
.rename(columns={'count':'nShpNm'})
.sort_values(by='nShpNm',ascending=False)
.head(20).print()
I could encapsulate the entire thing (sans .print()
) in a print()
invocation, but that’s another level of indentation. Just appending a print()
-like method avoids having to be much more cleaner, which makes a big difference when I have lots of these (for exploratory analysis). I can also toggle the output by simply commenting away the .print()
.