【发布时间】:2019-04-28 11:16:54
【问题描述】:
我在 Python 中多次使用format,但这个我遇到了麻烦。
解决方案应该很简单,但我不明白......
代码如下:
test_list = df.groupby(['gender', 'admitted'])['student_id'].count()
print('The quantity of female students are {}.'.format(test_list[0] + test_list[1])
test_list 的输出为:
gender admitted
female False 183
True 74
male False 125
True 118
Name: student_id, dtype: int64
所以,test_list[0] 是 183,test_list[1] 是 74。
打印的预期结果是:
The quantity of female students are 257.
【问题讨论】:
-
打印语句缺少结束')'
-
天啊!!!我为这些简单的错误花费了宝贵的时间。非常感谢。我很惭愧,大声笑!
标签: python dataframe syntax format