I am trying to display only selected columns from the pandas dataframe. logic is working but columns come with extra characters added to them.
Selected columns come inside Parentheses, quotes and coma. I got stuck on finding from where does it come and how to get rid of it.
Please Help.
import pandas as pd
import streamlit as st
df = pd.read_csv('data/AUDCAD_1h.csv')
st.sidebar.header('Data Filter')
col = st.sidebar.multiselect("Select any column",
df.columns)
if not col:
data = df.copy()
else:
data = df[col].values
data = pd.DataFrame(data, columns=[col])
st.write(data)
instead of
if not col:
data = df.copy()
else:
data = df[col].values
data = pd.DataFrame(data, columns=[col])
st.write(data)
N.B. Streamlit multiselect option returns a list.
Just use:
if not col:
data = df.copy()
else:
data = data[col]
st.write(data)