Reputation: 63
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```
Upvotes: 1
Views: 1354
Reputation: 261015
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
Upvotes: 2