0

这是我的代码使用streamlit

def main():

st.title(
    'Aplikasi Forecasting Exchange Rate')

def file_selector(folder_path='./datasets'):

    filenames = os.listdir(folder_path)
    selected_filename = st.selectbox("Select A file", filenames)
    return os.path.join(folder_path, selected_filename)

filename = file_selector()
st.info("Kamu memilih {}".format(filename))

# Read Data
dateparse = lambda dates: pd.datetime.strptime(dates,'%d-%m-%y')
akhir = pd.read_csv(filename, index_col=[0], date_parser=dateparse)
akhir['Terakhir'] = akhir['Terakhir'].str.replace(',', '').astype(float)

# Show Dataset
if st.checkbox("Show Dataset"):
    number = st.number_input("Number of Rows to View")
    st.dataframe(akhir.head(number))

当我想显示数据集 TypeError: cannot do slice indexing on with these indexers [0.0] of

4

1 回答 1

0

发生这种情况是因为默认number_input使用 0.01 的步长并且您没有指定任何函数参数,这意味着返回了一个浮点数。

要修复您的代码:

number = st.number_input("Number of Rows to View", min_value = 0, step = 1)

https://docs.streamlit.io/en/latest/api.html#streamlit.number_input

于 2020-05-26T19:09:53.817 回答