col_data.isnull().values.any()
时间: 2024-05-29 20:10:27 浏览: 14
This code checks if there are any null values in the entire DataFrame called "col_data".
If there is at least one null value in the DataFrame, the output will be True. If there are no null values, the output will be False.
相关问题
import pandas as pd import matplotlib.pyplot as plot raw_data = pd.read_csv(r'/Users/wangruihan/Desktop/time_series_covid19_confirmed_global.csv',na_values='?') #设定'?'为缺失值 #查看有哪些列 print(raw_data.columns) #查看前几行数据 print(raw_data[:10]) #检查含有缺失值的列 print(raw_data.isnull().any() ) print(raw_data.shape) #缺失值处理 print(raw_data[raw_data.isnull().values==True]) fill_na = lambda col:col.fillna('not know')#定义fill_na函数,用'not know'字符串填充缺失值 fill_data = raw_data.apply(fill_na, axis=0) #将填充后的数据赋给fill_data print(fill_data.isnull().any()) #检查是否填充成功 isDuplicated=fill_data.duplicated() #判断重复数据记录 print(isDuplicated) #初步了解数据构成 print(fill_data[fill_data['Country/Region']=='China']) data = fill_data.drop(['Province/State','Lat','Long'],axis=1) #删除属性列 data = data.groupby('Country/Region').sum() # 按Country/Region并求和 print(data.index.values) #列出全部可索引的Country/Region名称 data_us = data[data.index.isin(['US','China','United Kingdom','Italy','Germany','France'])] print(data_us) data_us.T.plot(figsize=(15,7)) #数据趋势图 最后数据趋势图不显示怎么办
如果你在Jupyter Notebook中运行这段代码并且没有看到数据趋势图,则可以在代码的最后加上`plt.show()`命令,如下所示:
```
data_us.T.plot(figsize=(15,7))
plt.show()
```
这个命令将显示图表并将其添加到Jupyter Notebook中。请注意,你需要首先导入matplotlib库,使用`import matplotlib.pyplot as plt`命令。
def get_data(): data = np.array(pd.read_csv('heart.csv')) disperse_col = [2, 6, 10, 11, 12] disperse_data, disperse_label = [], [] for i in disperse_col: col_data = data[:, i] col_label = list(set(col_data)) disperse_label.append(col_label) col_data = np.array([col_label.index(j) for j in col_data], dtype=np.int) col_data = np.eye(len(col_label))[col_data] disperse_data.append(col_data) disperse_data = np.concatenate(disperse_data, axis=-1) np.save('heart_disperse.npy', np.array(disperse_label)) 讲解一下每个语句的意思
这是一个 Python 函数,函数名为 get_data。函数内部首先读取一个名为 "heart.csv" 的 CSV 文件,并将数据存储在一个 numpy 数组 "data" 中。接下来,函数对数据进行了一些离散化处理,将原数据中的某些列进行了处理,其中第 2、6、10、11 和 12 列为离散化列。处理结果分别保存在 disperse_data 和 disperse_label 中。在处理离散化时,对于每一列数据,首先获取该列的所有取值,将这些取值作为标签存储在 disperse_label 中。然后遍历该列数据,根据取值在标签中的位置,将该列的数据转换成一个 one-hot 编码的向量,将所有列的编码向量拼接成一个大矩阵 disperse_data。最后将 disperse_label 保存为一个名为 "heart_disperse.npy" 的 numpy 数组文件。
相关推荐
![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)