大熊猫指定一个用notnull()过滤的系列,(Pandas Assigning back a series that was filtered with notnull())
各位开发人员,
我目前正在学习大熊猫,并且仍然试图围绕如何分配值,我将其转换为特定类型,例如回到原始数据框。
更具体的我有这个数据框:
id A B 0 50000 12413 32885.0 1 50001 2040 43737.0 3 50002 2040 28015.0 4 50003 2040 NaN 5 50004 2040 28565.0
我的目标是将
B
列转换为整数,但保留NaN
值,因此没有fillna(0)
。 我想要这个:id A B 0 50000 12413 32885 1 50001 2040 43737 3 50002 2040 28015 4 50003 2040 NaN 5 50004 2040 28565
我用
print(df.loc[df['B'].notnull(), 'B'].astype('int'))
做了这个print(df.loc[df['B'].notnull(), 'B'].astype('int'))
并且它有效。B 0 32885 1 43737 3 28015 4 28565
但是,如果我尝试将其分配回数据帧蒙山:
df.loc[df['B'].notnull(), 'B'] = df.loc[df['B'].notnull(), 'B'].astype('int')
我仍然得到原始的,未转换的数据。 所以我似乎做错了任务,但我无法弄清楚如何正确地做到这一点。 帮助将非常感谢!
Hello fellow developers,
I am currently learning pandas and still trying to wrap my head around how to assign values, that I converted to a specific type for example, back to the origin dataframe.
More specific I have this dataframe:
id A B 0 50000 12413 32885.0 1 50001 2040 43737.0 3 50002 2040 28015.0 4 50003 2040 NaN 5 50004 2040 28565.0
My goal is to convert column
B
to integers but leaveNaN
values as is, so nofillna(0)
. I want to have this:id A B 0 50000 12413 32885 1 50001 2040 43737 3 50002 2040 28015 4 50003 2040 NaN 5 50004 2040 28565
I did this with
print(df.loc[df['B'].notnull(), 'B'].astype('int'))
and it worked.B 0 32885 1 43737 3 28015 4 28565
But if I try to assign it back to the data frame whith:
df.loc[df['B'].notnull(), 'B'] = df.loc[df['B'].notnull(), 'B'].astype('int')
I still get the original, unconverted data. So I seem to do the assignment wrong, but I can't figure out how to do it correctly. Help would be much appreciated!
原文:https://stackoverflow.com/questions/50603794
最满意答案
我相信你的问题在标题部分。 我认为问题在于它周围缺少引号。
基本上,你需要确保
@(tecDoc.Text + " " + tecDoc.Value) = "Some text"
在Chrome上右键单击它并按“检查元素”以查看当前的外观。
另外,我建议添加数据放置标记。 只是为了确保它在各处看起来都一样:)
本来只是评论而不是回答,但所以不会让我..祝你好运! :)
I believe your issue is in the title section. I think the issue is the fact that it's lacking quotation marks around it.
basically, you need to make sure that
@(tecDoc.Text + " " + tecDoc.Value) = "Some text"
Right click it on Chrome and press "inspect element" to see what that currently looks like.
Also I suggest adding a data placement tag. Just to be sure it will look the same everywhere :)
Would have just commented instead of answering, but SO wont let me.. Good luck! :)
相关问答
更多-
您可以使用引导Tooltip Option trigger来处理这种情况。 如何触发工具提示 - 点击| 悬停| 重点| 手册。 你可能会传递多个触发器; 用空格分隔它们。 手动不能与任何其他触发器结合使用。 更多信息请阅读此处 点击这里查看工作演示 JS: $('[data-toggle="tooltip"]').tooltip({ trigger: "hover" }); You can use bootstrap Tooltip Option trigger to handle this ...
-
我可以在不隐藏它的情况下更改bootstrap工具提示的标题吗?(Can I change title of bootstrap tooltip without hiding it?)[2023-10-28]
好吧,问题是其他地方。 无论如何,现在我使用这个,因为这会更改所有需要工具提示的组件,其中上面的组件只更改一个组件。 $(".track a").tooltip('hide') .attr('data-original-title', time) .tooltip('fixTitle') .tooltip('show'); 初始化工具提示时,您必须将动画设置为false: $(".track a").tooltip({ 'animation' : false }); ... -
使用fixTitle选项更新工具提示。 $("#addRssbtn").attr("title", "Remove content from Personal RSS") 变 $("#addRssbtn").attr("title", "Remove content from Personal RSS").tooltip('fixTitle'); 您可以添加.tooltip('show'); 以后直接显示工具提示: $("#addRssbtn").attr("title", "Remove conten ...
-
MVC - 如何仅显示数据的单元格的引导工具提示(MVC - How to display bootstrap tooltip for the cells with data ONLY)[2022-03-06]
在td中添加跨度并在跨度上提供工具提示。 那么如果跨度中没有内容 - 隐藏它。 另外请注意,您需要为表格添加唯一的ID,这样如果您有多于一行的结构,可能需要修改#cost。@Html.DisplayFor(modelItem => item.Data.ProductId) @Html.DisplayFor(modelItem => item.Data.Product ... 在Bootstrap中将元素内容显示为工具提示的标题(Displaying element content as title for tooltip in Bootstrap)[2022-08-25]
$(document).ready(function(){ $('[data-toggle="tooltip"]').each(function(){ var url=$(this).prop('href'); $(this).tooltip({ html:true, title: $(url.substr(url.lastIndexOf('#'))).html() }) }) }); /* Tooltip */ .tooltip ...看来,你还没有包括jquery和所需的引导JavaScript文件 。 样式表和JavaScript的位置也很重要。 尝试将引导JavaScript文件和引导样式表文件放在其他样式表和JavaScript文件的末尾。 注意: id是唯一的! 使用class或data-toggle作为选择器是明智的。 $(function() { $('[data-toggle="tooltip"]').tooltip() });我相信你的问题在标题部分。 我认为问题在于它周围缺少引号。 基本上,你需要确保 @(tecDoc.Text + " " + tecDoc.Value) = "Some text" 在Chrome上右键单击它并按“检查元素”以查看当前的外观。 另外,我建议添加数据放置标记。 只是为了确保它在各处看起来都一样:) 本来只是评论而不是回答,但所以不会让我..祝你好运! :) I believe your issue is in the title section. I think the issue is th ...选择加入功能 出于性能原因,Tooltip和Popover data-apis是选择加入的,这意味着您必须自己初始化它们。 初始化页面上所有工具提示的一种方法是通过数据切换属性选择它们:复制 $(function () { $('[data-toggle="tooltip"]').tooltip() }) (来源: Bootstrap-Tabs ) 因此,您可以在关闭正文标记之前将其添加到html文件中: