Python-从CSV行+列读取将返回行号

总览

我想根据搜索在csv中返回列的值。我大部分时间都在那儿,但不明白为什么我得到了我想要的结果,以及如何解决它。我正在使用熊猫来读取csv。

问题:为什么我会收到行号,如何从返回结果中省略行号?

我的代码的子集如下:

code_ITS_path = 'c:/input_ITS.csv'
code_ITS = pd.read_csv(code_ITS_path,sep=',')

for trial_name in code_ITS.Trial_Name[code_ITS.Trial_Name.str.contains("Trial")]:
   scenario_name = code_ITS.Scenario_Name[code_ITS.Trial_Name.str.contains(trial_name)]
   print("Trial Name is " + trial_name)
   print("Scenario Name is " + scenario_name)

问题

返回的结果似乎包含“方案名称为”之前的行号。不幸的是,这以后会引起我一些问题。因此,打印出trial_name可行,但是打印出case_name则显示了问题。这里的问题是方案名称之前有“ 24”。 例如:

Trial Name is 500_10_3_Trial_24
24    Scenario Name is 500_10_3_24

期望的结果

我需要退货: 即,scenario_name不包含行号和制表符缩进

Scenario Name is 500_10_3_25

示例数据

CSV的示例:

Agency,Region,Requesting_Group,Scenario_Name,Type,Scenario_Description,Trial_Name,Notes
15,Main,,500_10_3_B,Operational,Testing,500_10_3_BestEstimate,None
15,Main,,500_10_3_1,Operational,Testing,500_10_3_Trial_1,None
15,Main,,500_10_3_2,Operational,Testing,500_10_3_Trial_2,None
15,Main,,500_10_3_3,Operational,Testing,500_10_3_Trial_3,None
15,Main,,500_10_3_4,Operational,Testing,500_10_3_Trial_4,None
15,Main,,500_10_3_5,Operational,Testing,500_10_3_Trial_5,None
15,Main,,500_10_3_6,Operational,Testing,500_10_3_Trial_6,None
15,Main,,500_10_3_7,Operational,Testing,500_10_3_Trial_7,None
15,Main,,500_10_3_8,Operational,Testing,500_10_3_Trial_8,None
15,Main,,500_10_3_9,Operational,Testing,500_10_3_Trial_9,None
15,Main,,500_10_3_10,Operational,Testing,500_10_3_Trial_10,None
15,Main,,500_10_3_11,Operational,Testing,500_10_3_Trial_11,None
15,Main,,500_10_3_12,Operational,Testing,500_10_3_Trial_12,None
15,Main,,500_10_3_13,Operational,Testing,500_10_3_Trial_13,None
15,Main,,500_10_3_14,Operational,Testing,500_10_3_Trial_14,None
15,Main,,500_10_3_15,Operational,Testing,500_10_3_Trial_15,None
15,Main,,500_10_3_16,Operational,Testing,500_10_3_Trial_16,None
15,Main,,500_10_3_17,Operational,Testing,500_10_3_Trial_17,None
15,Main,,500_10_3_18,Operational,Testing,500_10_3_Trial_18,None
15,Main,,500_10_3_19,Operational,Testing,500_10_3_Trial_19,None
15,Main,,500_10_3_20,Operational,Testing,500_10_3_Trial_20,None
15,Main,,500_10_3_21,Operational,Testing,500_10_3_Trial_21,None
15,Main,,500_10_3_22,Operational,Testing,500_10_3_Trial_22,None
15,Main,,500_10_3_23,Operational,Testing,500_10_3_Trial_23,None
15,Main,,500_10_3_24,Operational,Testing,500_10_3_Trial_24,None
15,Main,,500_10_3_25,Operational,Testing,500_10_3_Trial_25,None
评论