I am writing a df to a text file like so:
file = open("pptx_comparision_log.txt", "w")
df= df.to_string()
file.write(comp_df)
This works fine but how can I indent my df so it sits 5 white spaces to the right.
so from this:
dim_pptx qp_pptx
Absolute Radio 0.0739 0.0753
BBC Asian Network 0.0013 0.0013
BBC Radio 1 0.1441 0.1455
BBC Radio 1Xtra 0.0057 0.0058
BBC Radio 2 0.2336 0.2339
to:
dim_pptx qp_pptx
Absolute Radio 0.0739 0.0753
BBC Asian Network 0.0013 0.0013
BBC Radio 1 0.1441 0.1455
BBC Radio 1Xtra 0.0057 0.0058
BBC Radio 2 0.2336 0.2339
Is this possible?
Thanks.
You can just do it with string manipulation after the conversion by replacing df.to_string()
with " "*5 + df.to_string().replace("\n", "\n ")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With