[英]Fillna in Pandas
The code below is executing correctly: 下面的代码正确执行:
data['Native Country'].fillna(data['Native Country'].mode()**[0]**, inplace=True)
Can anyone explain what [0] indicates? 谁能解释[0]表示什么?
mode() method returns Series/DataFrame. mode()方法返回Series / DataFrame。
Check https://pandas.py.....as.Series.mode.html#pandas.Series.mode for Series & https://panda......i/pandas.DataFrame.mode.html for DataFrame. 检查https://pandas.py.....as.Series.mode.html#pandas.Series.mode中的Series和https://panda......i/pandas.DataFrame.mode.html中的DataFrame。
In your case, it returns Series object (as you are performing it on Series) even if there is a single value in Series. 在您的情况下,即使Series中只有一个值,它也会返回Series对象(与您在Series上执行时一样)。
Using [0] means we want to access the first value/item in the Series for replacement of null values. 使用[0]表示我们要访问Series中的第一个值/项目以替换空值。
Have a look at http://www.datasciencemadesimple.com/mode-function-python-pandas-dataframe-row-column-wise-mode/ . 看看http://www.datasciencemadesimple.com/mode-function-python-pandas-dataframe-row-column-wise-mode/ 。
This might help you a lot. 这可能对您有很大帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.