我想拥有:
df[['income_1', 'income_2']] * df['mtaz_proportion']
Run Code Online (Sandbox Code Playgroud)
返回那些列乘以 df['mtaz_proportion']
所以我可以设置
df[['mtaz_income_1', 'mtaz_income_2']] =
df[['income_1', 'income_2']] * df['mtaz_proportion']
Run Code Online (Sandbox Code Playgroud)
但相反,我得到:
income_1 income_2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... …
Run Code Online (Sandbox Code Playgroud) 将Pandas DataFrame
的所有列乘以存储在Series
?中的列向量的最佳方法是什么?我以前在Matlab中这样做repmat()
,在Pandas中不存在.我可以使用np.tile()
,但每次来回转换数据结构看起来很难看.
谢谢.
list
s,tuple
s,strings with separator
)?我已经看到了这些反复出现的问题,询问了大熊猫聚合功能的各个方面.今天关于聚合及其各种用例的大部分信息都是在数十个措辞严重,不可搜索的帖子中分散的.这里的目的是为后代整理一些更重要的观点.
此Q/A旨在成为一系列有用的用户指南中的下一部分: