简体   繁体   中英

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

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')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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