How to plot values from a dataframe?

52 Views Asked by At

I have a dataframe, test, that contains winter temperatures since 1951 for a city. I want to plot the temperatures contained in the column called wintermean but when I try to do that using plt.plot(test.wintermean.values) I get the following error: TypeError: cannot convert the series to <class 'float'>. Here's what test, wintermean, and test.wintermean.values looks like: enter image description here How can I plot this temperature data?

2

There are 2 best solutions below

0
not_speshal On BEST ANSWER

Looks like your DataFrame has a single row and the column value is a pandas.Series. To plot that series, try:

test["wintermean"].iloc[0].plot()
2
Yilmaz On

I think you need to clean up the data. there might be some non numerical values. For example "-" or "?". first convert those

 test['wintermean'] = pd.to_numeric(test['wintermean'], errors='coerce')

errors='coerce' will convert those non numerical values to Nan instead of throwing errors. then drop the Nan values

# drops Nan values in `winterman` column
test.dropna(subset=['wintermean'], inplace=True)