一直试图将我的DataFrame中的NaN值替换为最后一个有价值的项目,但这似乎不能完成这项工作。只是想知道是否有其他人有同样的问题或可能导致这个问题的原因。
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetUserServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String text = "<br>Message from servlet<br>"; //message you will recieve
String name = request.getParameter("name");
PrintWriter out = response.getWriter();
out.println(text + name);
}
}
非空值的数量没有变化,并且以前在数据框中仍然存在所有先前存在的NaN值
答案 0 :(得分:1)
您正在使用'pad'方法。这基本上是向前填充。请参阅http://pandas.pydata.org/pandas-docs/stable/missing_data.html
上的示例我在这里复制相关的例子,
In [33]: df
Out[33]:
one two three
a NaN -0.282863 -1.509059
c NaN 1.212112 -0.173215
e 0.119209 -1.044236 -0.861849
f -2.104569 -0.494929 1.071804
h NaN -0.706771 -1.039575
In [34]: df.fillna(method='pad')
Out[34]:
one two three
a NaN -0.282863 -1.509059
c NaN 1.212112 -0.173215
e 0.119209 -1.044236 -0.861849
f -2.104569 -0.494929 1.071804
h -2.104569 -0.706771 -1.039575
此方法不会进行回填。如果您希望所有NaN都消失,您还应考虑进行回填。此外,默认情况下为“inplace = False”。所以你可能想把操作的结果分配给ABCW ..就像这样,
ABCW = ABCW.fillna(method = 'pad')
ABCW = ABCW.fillna(method = 'bfill')