我有一个数据框架
,例如:store_id
,store_name
和number_of_orders
:
store_id name cbpr_ordes
0 900004468 [F] | Starbucks | STAR 013 1
1 900038719 Julice Boulangere Pães 1
对于每一行,我希望打印如下内容:“Hello,the(store_id)have(number_of_orders)in the last 15 minutes”
我试了一下:
for row in df:
print("Hello, the store_id " + str(df['store_id']) + " had " + str(df['cbpr_ordes']))
但我得到了:
Hello, the store_id 0 900004468
1 900038719
Name: store_id, dtype: object had 0 1
1 1
Name: cbpr_ordes, dtype: object
Hello, the store_id 0 900004468
1 900038719
Name: store_id, dtype: object had 0 1
1 1
Name: cbpr_ordes, dtype: object
Hello, the store_id 0 900004468
1 900038719
Name: store_id, dtype: object had 0 1
1 1
Name: cbpr_ordes, dtype: object
使用iterrows()函数:
for index, row in df.iterrows():
rows = dict(row)
print("Hello, the store_id " + str(rows['store_id']) + " had " + str(rows['cbpr_ordes']))