-1

I have a dictionary of daily temperature data for 3 stations TemmpDict. The keys are the station names and the values are the temperature data series. enter image description here I want to loop through this dictionary and create a data frame that contains the tmax data and mean tmax value for each station. I tried to do this with the following loop:

d=[]
for j in TempDict:
    df=TempDict[j]
    df.tmax=df.tmax.apply(pd.to_numeric,errors='coerce')
    d.append((df.tmax,df.tmax.mean()))
LargeFrame=pd.DataFrame(d,columns=('tmax','meanmax'),index=StationList)

This appears to work when I print LargeFrame. enter image description here But when I loop through and try to plot the tmax data for each station I get "TypeError: no numeric data to plot"

for j in LargeFrame:
    LargeFrame.tmax.plot()

How can I store this data in a data frame so that I can still plot it?

Megan Martin
  • 221
  • 1
  • 9
  • What data types do you see if you run ```LargeFrame.dtypes```? – sophocles Dec 06 '21 at 18:57
  • tmax: object and meanmax: float64. I tried "LargeFrame['tmax']=LargeFrame['tmax'].astype(float)" but get "ValueError: setting an array element with a sequence." – Megan Martin Dec 06 '21 at 19:00
  • So for the next error, you can refer to the following [link](https://stackoverflow.com/questions/13310347/numpy-valueerror-setting-an-array-element-with-a-sequence-this-message-may-app). It should probably be what you need. – sophocles Dec 06 '21 at 19:10
  • But how would I fix my code? I understand that this is a series but am not sure what to do about it – Megan Martin Dec 06 '21 at 19:26
  • Could you post a [sample of your data](https://stackoverflow.com/help/minimal-reproducible-example)? It will be easier for people to answer the question. Not me because i'm done for the day but other people :) – sophocles Dec 06 '21 at 19:27

1 Answers1

0

The issue isn't with how I'm storing the data, but with how I was looping through to LargeFrame to try to plot tmax. This is how I am able to get the plots I was looking for:

for index, row in LargeFrame.iterrows():
    LargeFrame.tmax[index].plot()
Megan Martin
  • 221
  • 1
  • 9