如何将excel文件中的所有Nan值一次设置为0

时间:2019-04-13 18:48:21

标签: python python-3.x pandas matplotlib seaborn

我想显示价格和年份之间的图表(数据是从csv文件中提取的),有2500多个数据条目,其中一些是NaN。我的图看起来很乱。

我的问题是由于这些NaN值,我已经尝试过

#df.isnull(0) and df.fillna(0)/df.fillna(0, inplace = true)

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('OLX_Car_Data_CSV.csv',delimiter=',',encoding="ISO-8859-1")
#print(df.shape)

df.fillna(0)
print(df.tail(5))

a = df.Price
b = df.Year

plt.plot(a,b , color = "blue")
plt.show()

plot preview

1 个答案:

答案 0 :(得分:0)

if value == countVowels(item): score = score + 1 print("Correct!") else: print("Incorrect! Correct answer is", countVowels(item)) 返回一个新的数据帧,您需要执行以下操作之一:df.fillna(0)df.fillna(0, inplace=True)