如果输入一些字符串,为什么不能获得预期的正确ID

时间:2018-11-14 13:55:08

标签: python

我有以下文件:

在这里,Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'topicServiceImpl': Unsatisfied dependency expressed through field 'topicGenerators'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.List<com.topic.service.TopicGenerator>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}是唯一的,而@Service可能是可重复的

id

我编写以下程序来实现自己的目标:例如

  • 如果用户输入名称Name,则程序将返回ID Name id Ajay 1 Ram 2 Ajay 3 Ram 4 Jack 6 Devid 7 的列表
  • 如果用户输入名称ajay,程序将返回ID [1,3]的列表

我的代码:

Ram

为什么不起作用?

1 个答案:

答案 0 :(得分:0)

通过python的库pandas可以很容易地做到这一点:

In [1952]: df = pd.read_fwf('file.txt')

In [1953]: df
Out[1953]: 
    Name   id
0   Ajay  1.0
1  Ram 2  NaN
2   Ajay  3.0
3  Ram 4  NaN
4   Jack  6.0
5  Devid  7.0

In [1957]: df[df.Name == 'Ajay']['id'].tolist()
Out[1957]: [1.0, 3.0]

只需用您从用户输入的变量替换Ajay

代码将更加整洁和小巧。让我知道是否有帮助。