2

I am trying to extract the column values from pandas dataframe but the output includes index and datatype as well. The code is given below

for index, row in df_count_unique3.iterrows():
policy_number = []
for value in row['p_number']:
    print(value)
    value = PC_number[(PC_number.p_number1 == value)&(PC_number.PRole == "AccountHolder")]
    policy_number.append(value['policy_number'])  
    PC_policy2['policy_number'] = policy_number


Output of PC_policy2
policy_number
2842824 P129487971 Name: policy_number, dtype..

Expected output:
policy_number
P129487971

Any suggestions would be great.

user3447653
  • 3,968
  • 12
  • 58
  • 100
  • https://stackoverflow.com/questions/24644656/how-to-print-pandas-dataframe-without-index – BENY Oct 31 '18 at 16:20
  • is p_number a column, if yes then why are you looping through it.. outer loop is doing that for you. just use the value using row['p_number'] – iamklaus Oct 31 '18 at 16:21

1 Answers1

2
print(df_count_unique3.to_string(index=False))
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58