Output of empty columns in streamlit aggrid saved as "None"

Dear friends,

first of all let me tell you how happy that I found streamlit. I am already testing it extensively. I have a question and would be really happy if you could support me.

I have following testframe

import pandas as pd
import numpy as np
import streamlit as st
from st_aggrid import AgGrid
testFrame=pd.DataFrame({"col1":[np.nan,1,2,4],"col2":[np.nan,np.nan,np.nan,np.nan]})
grid_return=AgGrid(testFrame, editable=True)
General=grid_return["data"]
new_df=General
st.write(new_df)

The output, however contains artefacts, I dont want to have, since in a later step I am saving the file as excel, and having them is not nice

col1         col2
<NA>	<NA>
1.0000	<NA>
2.0000	<NA>
4.0000	<NA>

I tried to use the command

new_df=new_df.replace("<NA">,"",regex=True)

but this does not work. I also tried some different things, but no success. Any suggestion?

Any support is more than appreciated :slight_smile:

new_df.fillna("", inplace=True) should do the trick

Dear blackary,

thanks for your help. Almost the solution.
However, if I change the cell value in Col2 in the browser (let’s say first row will be changed to 2) then I get the new_df blanks will be filled with .
The strange thing is that in the above example your solution works, but on my dataframe I get again the data if I change a cell value.
I also copied my original frame and applied the above codes on the copied one, but no succes.

Any idea why this happens?

@Isaak_Saba I’m not sure I totally understand the problem, but it might be solved by not actually saving the fillna, but just displaying it. This way, if you’re using new_df later on, it won’t have the NaN’s replaced with anything.

import numpy as np
import pandas as pd
import streamlit as st
from st_aggrid import AgGrid

testFrame=pd.DataFrame({"col1":[np.nan,1,2,4],"col2":[np.nan,np.nan,np.nan,np.nan]})
grid_return=AgGrid(testFrame, editable=True)
General=grid_return["data"]
new_df=General
st.write(new_df.fillna(""))

Does this do what you’re looking for?

Hi blackbary,

unfortunately not. It solves the testFrame I created, but not the Sheet I am uploading via file_uploader.

But the good thing is that I foud I workaround, which is the following.
Right after uploading the file and reading it as a frame I add the line

df.fillna(" ", inplace=True)

Then I do the following

grid_return=AgGrid(df, editable=True)
df=grid_return["data"]
df.replace(" ","",inplace=True)

Dont ask me why, but it’s working and I can save the excel without the “None” or “”

Thanks a lot for the inspiration :slight_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.