可以使用索引作为Python中的方法更改系列中的第一个值
以下代码为我提供了一些意外的输出。总而言之,我正在定义字典(dict2),然后从中创建一个系列。然后,我使用该系列方法重新分配了数学课程和科学课程的新价值。只有科学变化的价值(数学不变)。您能帮我理解为什么吗?谢谢。
编辑:我的目标是了解为什么它不能按预期工作,而不是实际重新分配数学价值。我还在这里添加了代码,而不是屏幕截图。谢谢。
dict2 = {'数学':60,'科学':89,'英语':76,'社会科学':86}
marks_series = pd.series(dict2)
print(marks_series)
marks_series.maths.maths.maths = 65
marks_series.series.science = 90
打印(Marks_Series)
The following code is giving me some unexpected output. In summary, I am defining a Dictionary (dict2) and then creating a series out of it. Then, I am re-assigning a new value to the Math course and the Science course using the Series' method. Only the value for Science changes (and for Math it is unchanged). Can you please help me understand why? Thank you.
Edit: My goal is to understand why this is not working as expected, rather than actually reassigning a value to Math. I've also added the code here instead of the screenshot. Thank you.
dict2 = {'Maths': 60, 'Science': 89, 'English': 76, 'Social Science': 86}
marks_series = pd.Series(dict2)
print(marks_series)
marks_series.Maths = 65
marks_series.Science = 90
print (marks_series)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我重新启动了笔记本,这解决了问题。我仍然想知道为什么它首先发生。但这是另一天。
I restarted my notebook and that fixed the issue. I still wonder why it happened in the first place. But that's for another day.
根据重播和信息,您的代码正常工作,问题可能是导入大熊猫和您的env
According to replays and info , your code working correctly and the problem may be case of importing pandas and your Env