Problems with separator of thousands in DataFrame loaded from Excel

Hi every one.

i’m loading a DataFrame from excel with this structure:

The code is the following:
imagen

import streamlit as st
import pandas as pd

st.set_page_config(page_title='Censo Bovino - Datos',
                page_icon=':ox:',
                layout='wide')

st.sidebar.header("Demo Datos")

st.sidebar.markdown('---')

st.title('Datos')

st.markdown('---')

@st.cache_data
def load_data():
    df= pd.read_excel(
        io='CENSOS-BOVINOS-2023-Final.xlsx',
        engine='openpyxl',
        sheet_name='BOVINOS Y PREDIOS',
        skiprows=4,
        usecols='A:Q',
        nrows=1121,
        thousands='.'
        )

    return df
    
df = load_data()

st.dataframe(df)

But, when I want to use the data in Streamlit, it looks like this:
imagen

As you can see, Streamlit change the β€œ.” by β€œ,” so when I plot, the legends look like this: β€œTotal = 2,345678” instead of looking like this "Total = 2.345.678.

Any suggestions?

Having actual data and code instead of pixels would help.

1 Like

Finally I fix the issue like this:

import streamlit as st
import pandas as pd
import plotly.graph_objs as go

@st.cache_data
def load_data():
    df=pd.read_excel(
        io='CENSOS-BOVINOS-2023-Final.xlsx',
        engine='openpyxl',
        sheet_name='BOVINOS Y PREDIOS',
        skiprows=4,
        usecols='A:Q',
        nrows=1121,
        #thousands='.'
    )

    return df

df = load_data()

# this line, fixes how the data is viewed.
st.dataframe(df.style.format(thousands='.'))

imagen

The code for the plot:

with open ('Colombia.geo.json') as response:
    Departamentos = json.load(response)

locs = df['DEPARTAMENTO']

for Departamento in Departamentos['features']:
    Departamento['id'] = Departamento['properties']['NOMBRE_DPT']
mapa = go.Figure(go.Choroplethmapbox(
                    geojson=Departamentos,
                    locations=locs,
                    z=df[variables],
                    colorscale='prgn_r',
                    colorbar_title=f'{variables}to.',
                   #This line sets the correct visualization for the labels
                    hovertemplate='%{z:.4s} <extra>%{location}</extra>',
                    ))
mapa.update_layout(mapbox_style="carto-positron",
                        mapbox_zoom=4.3,
                        height=700,
                        margin=dict(
                            l=10,
                            r=10,
                            b=10,
                            t=10,
                            pad=5
                            ),
                        
                        paper_bgcolor='rgba(50, 50, 50, 0.5)',
                        mapbox_center = {"lat": 4.570868, "lon": -74.2973328})

st.plotly_chart(mapa, use_container_width=True)

imagen

1 Like

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