Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python pandas: removing name and dtype in iterrows

i’m currently working on an inventory systsem.
How do i remove "Name:,dtype:" in the iterows?
Or is there other way that I can show the row’s info ?
Thanks

1 Name                  cat
Unit Price          $2.00
Quantity                2
Price               $4.00
Expiry Date    0002-02-02
Expired?               No
Name: 1, dtype: object
2 Name                    2
Unit Price          $2.00
Quantity                2
Price               $4.00
Expiry Date    2003-02-02
Expired?               No
Name: 2, dtype: object
3 Name                  dog
Unit Price          $2.00
Quantity                2
Price               $4.00
Expiry Date    0002-02-02
Expired?               No
Name: 3, dtype: object
4 Name                mouse
Unit Price          $3.00
Quantity                3
Price               $9.00
Expiry Date    0003-03-03
Expired?               No
Name: 4, dtype: object
5 Name                    3
Unit Price          $3.00
Quantity                3
Price               $9.00
Expiry Date    0003-03-03
Expired?               No
Name: 5, dtype: object```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should use the Series.to_string method before printing:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randint(0,10,(3,4)))

for name,s in df.iterrows():
    print(f'row: {name}')
    print(s.to_string())  # to_string outputs only the data, not the metadata

example:

row: 0
0    9
1    0
2    9
3    5
row: 1
0    1
1    2
2    5
3    6
row: 2
0    0
1    1
2    5
3    5
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading