Range("A1").value = p.df_sector[["A","B","C"]].sort(columns=["C"],ascending=False).head(4)
Works wonderfully! But - I do not want/need to see the index
column
p.df_sector[["A","B","C"]].sort(columns=["C"],ascending=False).head(4).to_string(index=False)
Would do what I need, but then the data deposits in a single cell!
.to_matrix()
Does what I need but then I lose my headers (which I require).
Any input on how to dump the df
with headers and without index?
The documentation and syntax seems to have changed a bit, since 2015.
Here is the documentation for dealing with Pandas via xlwings.
Instead of a parameter in Range
, index=False
needs to be inside a .options
. So if you're dealing with worksheet sht
in your code, the left-hand side of your equation should be
sht.range('A1').options(index=True).value = ...
There's an example in the docs about working with pandas. Also check the docs about Range. In your case:
sht.range("A1").options(index=False).value = p.df_sector[["A","B","C"]].sort(columns=["C"],ascending=False).head(4)
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