【发布时间】:2020-02-17 19:21:34
【问题描述】:
for i in str_list: #str_list is a set contain some strings
df.loc[i].sort_values(by = 'XXX')
**TypeError**: sort_values() got an unexpected keyword argument 'by' ".
>>> type(df.loc[i])
>>> pandas.core.frame.DataFrame
但它可以在 for 循环之外工作!
df.loc['string'].sort_values(by = 'XXX')
>>> type(df.loc['string'])
>>> pandas.core.frame.DataFrame
我很困惑。
【问题讨论】:
-
df.loc[something]可能会返回一个系列或一个数据帧。如果something在索引中出现多次,则结果是一个DataFrame。