1

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```
ineedmoney
  • 63
  • 7
  • You have a list of `Series`? – Corralien Jan 08 '22 at 13:03
  • I think this (https://stackoverflow.com/questions/29645153/remove-name-dtype-from-pandas-output-of-dataframe-or-series) answers your question! – Matteo Zanoni Jan 08 '22 at 13:05
  • what are you trying to do? if you're just printing data then why should it matter since this only appears when you print – gold_cy Jan 08 '22 at 13:05
  • Does this answer your question? [Remove name, dtype from pandas output of dataframe or series](https://stackoverflow.com/questions/29645153/remove-name-dtype-from-pandas-output-of-dataframe-or-series) – gold_cy Jan 08 '22 at 13:05
  • You do not give the initial dataframe, nor the code you have used to obtain (and print) that sequence of Series, and to not even show the expected output... How can we help you :-( – Serge Ballesta Jan 08 '22 at 13:06

1 Answers1

2

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
mozway
  • 194,879
  • 13
  • 39
  • 75