我目前正在研究庫存系統。如何洗掉 itrows 中的“Name:,dtype:”?還是有其他方法可以顯示該行的資訊?謝謝
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```
uj5u.com熱心網友回復:
您應該Series.to_string在列印之前使用該方法:
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
例子:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/405987.html
標籤:
