Pandas, print variable in string

  • A+
Category:Languages

I have a dataframe (new) that looks something like this:

num  name1  name2 11    A      AB 14    Y      YX 25    L      LS 39    Z      ZT .... 

and I just want to extract the num value in a print statement such that I have an output that looks like this:

The value is 11 The value is 14 The value is 25 ... 

I'm not sure what the correct format to do this is, as the following bit of code just iterates "The value is".

 for index, row in new.iterrows():      print('The value is').format(new['num']) 


Slightly change your code

for index, row in df.iterrows():     print('The value is {0}'.format(row['num']))  The value is 11 The value is 14 The value is 25 The value is 39 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: