在数据框中创建新列的问题
我帮助将以下各列添加到数据框中,非常感谢任何指导。我创建了变量: no_outlier_pe_go ['industry_marketCap']= _outlier_pe_g.groupby('industry')['marketCap'].transform(' sum')
但一旦我尝试创建后续列(下面的说明和屏幕截图),就会不断出现错误。
使用此变量创建行业 PE 作为行业股票的市值加权 PE,并将其命名为 'ind_pe'
。 (提示:您需要一列反映行业中每只股票的市值权重,'wt_in_industry'
,另一列用于反映跟踪PE与其行业权重的乘积,并将其命名为pe_ind_wt。使用转换方法在后一个变量上创建 ind_pe 作为 pe_ind_wt 的总和)。
I help with adding the below columns to a data frame, any guidance is much appreciated.I created the variable: no_outlier_pe_go ['industry_marketCap']= _outlier_pe_g.groupby('industry')['marketCap'].transform('sum')
but keep getting errors once I try to create the subsequent columns, (instructions and screenshot below).
Use this variable to create an industry PE as a marketCap weighted PE of stocks in the industry and name it 'ind_pe'
. (Hint: you need a column that reflect the marketCap weight of each stock in the industry, 'wt_in_industry'
, another column for the product of trailingPE by its industry weight and name it pe_ind_wt. Use the transform method on the latter variable to create ind_pe as the sums to pe_ind_wt ).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您将
no_outlier_pe_g
创建为另一个DataFrame
的副本。您可以通过 df._is_copy 进行检查,如下所示:从技术上讲,这只是一个警告而不是错误。
SettingWithCopyWarning
警告您,您正在处理DataFrame
的副本,这会使原始DataFrame
保持不变,并可能导致意外结果,例如链接的结果运营。它已在在您的用例中,如果您意识到可能存在的不一致,那就没问题。
I suspect you created
no_outlier_pe_g
as a copy of anotherDataFrame
. You can check so bydf._is_copy
, as shown here:Technically, it's just a warning not an error. The
SettingWithCopyWarning
warns you that you work on a copy of theDataFrame
, which leaves the originalDataFrame
unaltered and might lead to unexpected results e.g. with chained operations. It has been discussed extensively in the docs.In your use case it's fine, if you are aware of the possible inconsistencies.