Mady
Mady3mo ago

Freeze Column Table Argument Not Working as Expected

I'm trying to use the freeze_columns_left argument in mo.ui.table, and I am not getting an error, but the specified column is not frozen. This is my code. Can you tell me why?
No description
19 Replies
eugene
eugene3mo ago
I think you forgot to add freeze_columns_left=["Name"] inside the if condition 🤔
Mady
MadyOP3mo ago
That is 100% true, I thought I was testing with something that didn't meet the condition but maybe not because I just walked away and came back and it was working 🤦🏼‍♀️ Is it possible to make the dataframe's index freeze?
eugene
eugene3mo ago
You are using polars right? maybe you can try
mo.ui.table(
df[mask].with_row_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["index", "Name"],
)
mo.ui.table(
df[mask].with_row_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["index", "Name"],
)
I think you need to create a new cell and run the code there Edit in-place doesn't change the pinning, but seems to be fixed in the next release
Mady
MadyOP3mo ago
I was using pandas!
eugene
eugene3mo ago
sorry, I saw you were indexing with mask so assumed that you were using polars then
mo.ui.table(
df[mask].reset_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["index", "Name"],
)
mo.ui.table(
df[mask].reset_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["index", "Name"],
)
should work?
Mady
MadyOP3mo ago
Sorry, I was following a tutorial on how to "mask" a data frame table to only show values selected on a plotly chart! I will probably not get back to this until later today but will try that out.
Mady
MadyOP3mo ago
I didn't get this to work - just to clarify, I'm referring to the dataframe index, not a column called index
No description
Mady
MadyOP3mo ago
for context, I'm trying to get the column called "Number" (which is the dataframe index) to freeze on the left
No description
eugene
eugene3mo ago
In this case, just freeze_columns_left=["Number, "Name"] should work?
eugene
eugene3mo ago
df.reset_index() should automatically generate a column named "index"
No description
Mady
MadyOP3mo ago
this is what I get
No description
Mady
MadyOP3mo ago
and this is what I get when I try this
No description
eugene
eugene3mo ago
is "Number" in team_df2[mask].columns? also, you forgot () inside the if condition for reset_index
Mady
MadyOP3mo ago
my bad on reset_index, but fixing that still didn't change the behavior. and no, it is not in team_df2[mask] because it is the dataframe's index
eugene
eugene3mo ago
my bad, have limited experience with pandas the only solution I can come of is setting "Number" to a regular column instead of index I think freeze_columns_left ignores index column for pandas
Mady
MadyOP3mo ago
is there a way to not display the index in the table then? because if it isn't the index, then it wants to show a serialized/default index column in the table also
eugene
eugene3mo ago
maybe
mo.ui.table(
df[mask].reset_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["Number", "Name"],
)
mo.ui.table(
df[mask].reset_index(),
show_column_summaries=False,
selection=None,
pagination=None,
freeze_columns_left=["Number", "Name"],
)
this should reset the "Number" index to a regular column
Mady
MadyOP3mo ago
So this is kind of working as I expected..... the thing I am finding weird is that if I put index in the freeze list after using reset_index, it does freeze the auto-assigned index.
No description
Mady
MadyOP3mo ago
for some reason you only cannot assign index in freeze_columns_left when index is defined by a dataframe column, not when the default auto-assigned index is used