0

I have been trying to plot a lot of different time series against each others but I am unable to create a scatter_matrix.

Print(ptExcitationInside.as_matrix) returns :

[[<bound method NDFrame.as_matrix of                  Particle excitation inside(j)
date                                      
2017-03-07 08:00:00.779                7.0
2017-03-07 08:00:00.780                7.0
2017-03-07 08:00:00.781                7.0
...                                    ...
2017-03-06 14:34:32.041              168.0
2017-03-06 14:34:32.042              169.0

[23671264 rows x 1 columns]>]]

and Print(ptExcitationOutside.as_matrix) returns :

<bound method NDFrame.as_matrix of                          Particle excitation outside(j)
date                                      
2017-03-06 08:00:00.779               47.0
2017-03-06 08:00:00.780               47.0
2017-03-06 08:00:00.781               47.0
...                                    ...
2017-03-06 14:34:32.041              168.0
2017-03-06 14:34:32.042              169.0
[23671264 rows x 1 columns]>]]

I would like to use scatter_matrix to look at the correlation between the variables. (I have more than 2 time series like these, these are just examples)

I tried to create a big matrix observables = np.matrix[ptExcitationInside.as_matrix, ptExcitationOutside.as_matrix][ptExcitationInside.as_matrix, ptExcitationOutside.as_matrix] and pd.scatter_matrix(observables) but it returns :

AttributeError                            Traceback (most recent call last)
<ipython-input-232-218b3e0bf63a> in <module>()
 ----> 1 pd.scatter_matrix(observables, c='blue', alpha = 0.5, figsize = (10, 10), diagonal = 'kde');

/louis/anaconda3/lib/python3.6/site-packages/pandas/tools/plotting.py in scatter_matrix(frame, alpha, figsize, ax, grid, diagonal, marker, density_kwds, hist_kwds, range_padding, **kwds)
343     import matplotlib.pyplot as plt
344 
--> 345     df = frame._get_numeric_data()
346     n = df.columns.size
347     naxes = n * n

AttributeError: 'matrix' object has no attribute '_get_numeric_data'

so I tried to get only the value column but print((ptExcitationInside.as_matrix)[:,0]) returns :

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-227-b6ec50a21c53> in <module>()
  1 
----> 2 print((ptExcitationInside.as_matrix)[:,0])

TypeError: 'method' object is not subscriptable

Can someone help me, I am new to Python (first week on it), I am a C/Java developer and I don't know how to understand what variable types I am using.

EDIT :

<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 23671264 entries, 2017-03-07 08:00:00.779000 to 2017-03-07 14:34:32.042000 
Freq: L Data columns (total 1 columns): Particle excitation inside float64 
dtypes: float64(1) memory usage: 361.2 MB 
<class 'pandas.core.frame.DataFrame'> 
DatetimeIndex: 23671264 entries, 2017-03-07 08:00:00.779000 to 2017-03-07 14:34:32.042000 
Freq: L Data columns (total 1 columns): Particle excitation outside 
float64 dtypes: float64(1) memory usage: 361.2 MB 
L.Ech
  • 21
  • 6
  • There are a couple of things here that needs fixing: 1. You don't need to convert a dataframe to a matrix to use the `pd.scatter_matrix` function. 2. Even if you did need to convert your dataframe to matrix, `as_matrix` is a method not an attribute. So you would need to do `ptExcitationInside. as_matrix()` instead. 3. Your dataframes seem to all share a common index `date`, so `merge` them into a ***bigger dataframe*** by the `date` index and then use the `pd.scatter_matrix` on that bigger dataframe. – Abdou Mar 07 '17 at 03:21
  • I have a datetime index but not a column to merge on : DatetimeIndex: 23671264 entries, 2017-03-07 08:00:00.779000 to 2017-03-07 14:34:32.042000 Freq: L Data columns (total 1 columns): Particle excitation inside float64 dtypes: float64(1) memory usage: 361.2 MB DatetimeIndex: 23671264 entries, 2017-03-07 08:00:00.779000 to 2017-03-07 14:34:32.042000 Freq: L Data columns (total 1 columns): Particle excitation outside float64 dtypes: float64(1) memory usage: 361.2 MB – L.Ech Mar 07 '17 at 05:24
  • I found how to merge DataFrame on Index thanks to : http://stackoverflow.com/questions/36292959/pandas-merge-data-frames-on-datetime-index Thank you Abdou – L.Ech Mar 07 '17 at 05:39

0 Answers0