Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot dataframe columns against each other

I have this df :

      CET    MaxTemp  MeanTemp MinTemp  MaxHumidity  MeanHumidity  MinHumidity  revenue     events
0  2016-11-17   11      9        7            100           85             63   385.943800    rain
1  2016-11-18   9       6        3             93           83             66  1074.160340    storm
2  2016-11-19   8       6        4             93           87             76  2980.857860    
3  2016-11-20   10      7        4             93           84             81  1919.723960    rain-thunderstorm
4  2016-11-21   14     10        7            100           89             77   884.279340
5  2016-11-22   13     10        7             93           79             63   869.071070
6  2016-11-23   11      8        5            100           91             82   760.289260    fog-rain
7  2016-11-24   9       7        4             93           80             66  2481.689270
8  2016-11-25   7       4        1             87           74             57  2745.990070
9  2016-11-26   7       3       -1            100           88             61  2273.413250    rain 
10 2016-11-27  10       7        4            100           81             66  2630.414900    fog

Where:

CET                  object
Mean TemperatureC     int64
Mean Humidity         int64
Events               object
revenue              object
dtype: object

I want to plot all the columns against each other, to see how they variate over time. So, x-axis will be column CET and y-axis will have the rest of the columns. How can I do that? I used:

plt.figure();
df.plot(kind='line')
plt.xticks(rotation='vertical')
plt.yticks()
pylab.show()

but I can only see the Mean TemperatureC and Mean Humidity. Moreover, the x-axis is not CET date values, but the row number

like image 205
joasa Avatar asked Mar 10 '23 06:03

joasa


1 Answers

As far as I remember plot uses the index for the x values. Try:

df.set_index('CET').plot()

And you should make sure that all you columns have a numeric datatype.

Edit:

df = df.set_index('CET')
num_cols = ['MaxTemp',
            'MeanTemp',
            'MinTemp',
            'MaxHumidity',
            'MeanHumidity',
            'MinHumidity',
            'revenue']
df[num_cols] = df[num_cols].astype(float)
df[num_cols].plot()
plt.xticks(range(len(df.index)), df.index)
like image 194
Jan Zeiseweis Avatar answered Mar 13 '23 02:03

Jan Zeiseweis