简体   繁体   English

如何从数据集中删除缺失的数据并绘制散点图

[英]How to remove the missing data from the dataset and plot the scatter plot

我的问题是如何从数据集中删除缺失的数据并绘制散点图,有人可以帮助我解决这个问题,请绘制

You can convert the lists you have into a dataframe df using pd.DataFrame and then use .dropna() to drop the rows that have nan values and then in the end use plt.scatter from Matplotlib to plot the scatter plot您可以使用pd.DataFrame将您拥有的列表转换为数据df ,然后使用.dropna()删除具有nan值的行,然后最后使用Matplotlib 中的 plt.scatter 绘制散点图

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Hp = [10050, 42300, 50206, np.nan, 105000, np.nan, 22350]
nr = [np.nan, 4,5,6,10,12,2]

df = pd.DataFrame({
        'Price':Hp,
        'Rooms':nr
        })
df = df.dropna(axis=0)

plt.scatter(x = df['Price'],y= df['Rooms'])
plt.xlabel('House Price')
plt.ylabel('Rooms')

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM