0
Name    Date of Birth   Favourite fruit
John    06.07.1989      Apple
Tim     12.03.1999      Kiwi
Kelly   ...             ... 
Borris  ...             ...
...     ...             ...

I'm looking to print out all of my table (infinite, got a script that adds to it), It should look something like this (doesn't nessercerly have to look like this, just as example):

OUTPUT:
(John(born: 06.07.1989, fruit: Apple)), (Tim(born: 12.03.1999, fruit: Kiwi))

How can I loop this proccess, of taking value by value and printing it out? I've never worked pandas before. I'm lost at this point.

Thank you in advance

3
  • 2
    What have you tried so far? Is your table in a .csv file or have you already read it into a pandas DataFrame? Commented Aug 19, 2021 at 20:21
  • It is totally unclear what you are trying to do. What is your "table"? Is this some text file on your disk? How would pandas be involved here? Commented Aug 19, 2021 at 20:28
  • If your file is in principle infinite then don't use pandas because pandas will attempt to read all into memory. If it is a .csv then use the csv module. If it is something else you need to present a sample. Commented Aug 19, 2021 at 21:20

1 Answer 1

1

Please, use .format function with ** to get cells without other symbols.

In '...'.format(..) you can insert column names this way {Name}. Try this:

 import pandas as pd     

 df=pd.read_excel("yourfile.xlsx")
 nlist=['({Name}(born: {Date of Birth}, fruit: {Favourite fruit})),'.format(**df.iloc[x]) for x in df.index]    
 print(*nlist)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.