类型错误:无法使用<类"float"的这些索引器 [0.0] 对<类"pandas.core.indexes.datetimes.DatetimeIndex">执行切片索引>



这是我的代码使用 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))

当我想显示数据集时出现错误 类型错误: 无法使用这些索引器 [0.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

最新更新