Home > Software engineering >  How do i fix values must be a 1D array problem in pandas
How do i fix values must be a 1D array problem in pandas

Time:10-29

df["TROL10"].values  

I get this which seems to me that its a 1D array. Do you have any ideas?

[18.604038230955343, 18.670614362306086, 18.646735605154216,
 18.656236215707576,  18.53352615271398, 18.537702884272235,
 18.448225333878803, 18.355757101875124,  18.20601450637466,
 18.160600591544057,  18.13380762932929, 18.034593494718145,
 17.950137698176437,  17.87131617610324,  17.87661036759285,
 17.791582399374334, 17.840878239393277,  17.77368955956415,
 17.712932564513817, 17.593807522663035, 17.528720974631437,
 17.569683995275437, 17.495345618314875,  17.45466774254079,
 17.429889960592973, 17.494336028145792, 17.532905610808747,
 17.503039219365693,   17.5860857196472, 17.780398532824318,
 17.909579658472524, 17.870647851379257,  17.95176205667108,
 18.005518826259493, 18.126175175198767, 18.211852627985856,
 18.349079574880196, 18.495299900821262, 18.547974301845898,
 18.491714065403823,  18.43596777154002, 18.434644986531357,
 18.464600010234033, 18.514984547670664, 18.514486649449985,
 18.529428325473493, 18.524350534809535, 18.446600412835394,
 18.447354325389387, 18.577178082191782, 18.638549071120305,
 18.801725876448224,  18.85516122233934, 18.970825102659326,
 19.028430552743707, 19.016882970334628, 18.986930728672984,
 19.122546933524852,   19.1271569632681,  19.10994756706495,
  19.35443247582892, 19.303999834778512,  19.45680060316427,
  19.40531602255797,  19.72797110743794, 19.545107804925124]
Length: 66, dtype: Float64

and then when after the following line I get the ValueError and I'm sure that the df["DATE"] isn't causing the problem because I have already used that earlier with zero problems.

plt.plot(df['DATE'], df["TROL10"])

and i get
ValueError: values must be a 1D array

CodePudding user response:

I think I see it now. Are you using pandas.array to create the columns of the DataFrame? If you use numpy arrays instead it should work as you expect.

You can also call .to_numpy() on the pandas arrays.

CodePudding user response:

The data plots ok.

array=np.array([18.604038230955343, 18.670614362306086, 18.646735605154216,

18.656236215707576, 18.53352615271398, 18.537702884272235, 18.448225333878803, 18.355757101875124, 18.20601450637466, 18.160600591544057, 18.13380762932929, 18.034593494718145, 17.950137698176437, 17.87131617610324, 17.87661036759285, 17.791582399374334, 17.840878239393277, 17.77368955956415, 17.712932564513817, 17.593807522663035, 17.528720974631437, 17.569683995275437, 17.495345618314875, 17.45466774254079, 17.429889960592973, 17.494336028145792, 17.532905610808747, 17.503039219365693, 17.5860857196472, 17.780398532824318, 17.909579658472524, 17.870647851379257, 17.95176205667108, 18.005518826259493, 18.126175175198767, 18.211852627985856, 18.349079574880196, 18.495299900821262, 18.547974301845898, 18.491714065403823, 18.43596777154002, 18.434644986531357, 18.464600010234033, 18.514984547670664, 18.514486649449985, 18.529428325473493, 18.524350534809535, 18.446600412835394, 18.447354325389387, 18.577178082191782, 18.638549071120305, 18.801725876448224, 18.85516122233934, 18.970825102659326, 19.028430552743707, 19.016882970334628, 18.986930728672984, 19.122546933524852, 19.1271569632681, 19.10994756706495, 19.35443247582892, 19.303999834778512, 19.45680060316427, 19.40531602255797, 19.72797110743794, 19.545107804925124])

x=np.linspace(1,len(array),len(array))
plt.plot(x,array)
plt.show()
  • Related