Reputation: 6835
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?
Upvotes: 4
Views: 10236
Reputation: 7070
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)
Upvotes: 4
Reputation: 5068
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 = ...
Upvotes: 7