问题描述
我已经编写了与用户输入交互的 python while 循环。
有一个带有日期列的表格。
这个想法是询问用户是否要从表中删除列。如果是,则需要从给定列表中指定列。它删除列并再次询问是否需要删除更多列,直到得到答案否,然后保存表。
问题:如果用户想要删除超过 1 列,循环不再接受/理解列名称。
脚本:
x=input('Would you like to drop columns? ')
print(x)
if x=='yes':
print('The available columns will be print now. please select each time only one column.')
print('available columns are:',new_dates)
d_bye=input('date to drop:')
print(d_bye)
df.drop(d_bye,axis=1,inplace=True)
rep=input('do you have more columns to drop?')
print(rep)
while rep == 'yes':
d_bye=input('column to drop:')
df.drop(d_bye,inplace=True)
print(rep)
if rep=='no':
break
else:
print('please type yes or no!')
print(rep)
df.to_csv(result_table)
'Process accomplished!'
这个在特定情况下的输出是:
Would you like to drop columns? yes
yes
he available columns will be print now. please select each time only one column.
available columns are: ['a','b','c','d']
date to drop: a
a
do you have more columns to drop? yes
yes
column to drop: c
yes
please type yes or no!
yes
columnn to drop: d
yes
please type yes or no!
yes
column to drop: no
如您所见,在它丢弃第一个(我检查过并且确实如此)之后,对于第二个和第三个它不起作用。我怎样才能让它在 while 循环内从更多列中取出?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)