pandas.core.frame.DataFrame如何取出前两列并转为numpy类型
时间: 2024-03-24 13:37:55 浏览: 21
DAO.insertStudent(newStudent);
response.sendRedirect("list");
}
private void updateStudent(HttpServletRequest request, HttpServletResponse response)
throws SQLException可以使用`iloc`方法来取出DataFrame的前两列,再使用`to_numpy()`方法将其转换为numpy数组, IOException {
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String gender = request,例如:
```python
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, 2,.getParameter("gender");
int age = Integer.parseInt(request.getParameter("age"));
String dormitory = request.getParameter("dormitory");
3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
np_array Student student = new Student(id, name, gender, age, dormitory);
studentDAO.updateStudent(student);
response.sendRedirect("list = df.iloc[:, :2].to_numpy()
print(np_array)
```
输出结果为:
```
[[1 4]
[2");
}
private void deleteStudent(HttpServletRequest request, HttpServletResponse response)
throws SQLException, IOException {
int id = Integer.parseInt(request.getParameter 5]
[3 6]]
```
其中,`iloc[:, :2]`表示取所有行,前两列的数据,即第一列和第二列。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)