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
Run Code Online (Sandbox Code Playgroud)
但是它在for循环之外起作用!
df.loc['string'].sort_values(by = 'XXX')
>>> type(df.loc['string'])
>>> pandas.core.frame.DataFrame
Run Code Online (Sandbox Code Playgroud)
我糊涂了。