2

Hi I am new to python and working with jupyter notebook, so any help would be greatly appreciated!.

I am having trouble plotting a scatter matrix. I have imported my csv file and I have a column with 'Names' of drugs. So I want to get how many times this drug occurs so I use

name = Crimes['drug name'].value_counts()
name

This returns how many times a specific drug has been called as 'drug name' is the column in my csv file

I have tried to plot a scatter matrix like so:

%matplotlib inline
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
scatter_matrix(name, alpha=0.2, figsize=(6, 6), diagonal='kde')

However I am getting an error 'Series' object has no attribute 'columns'

Does anyone know how I can fix this issue? Thanks in advance

Katie
  • 45
  • 1
  • 7

3 Answers3

0

You cannot pass pandas.core.series.Series to scatter_matrix function because it accepts only Dataframes with morethan one column(This is not in documents). Please read the documentation. Screenshot for reference.screen shot for reference. Also the Scatter_plot is used to represent the distributions of columns comparing with all other columns check the reference: Pandas scatterplot. The error is due to it is accessing the columns in the dataframe where as you are using Series which do not have columns that is the main reason. These are the possible reasons. Correct me if wrong.

Space Impact
  • 13,085
  • 23
  • 48
  • @Katie for better understanding of data use bar chart. Since the drug name is categorical type it is good to use bar chart to get more insights about data. – Space Impact Nov 22 '17 at 16:16
0

If you want to print scatter_matrix with only one column of data

scatter_matrix(data_frame[['column_name']])

el2e10
  • 1,518
  • 22
  • 22
0

Matplotlib had a scatterfunction, ”https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html” which i would suggest!

Aristotes
  • 41
  • 1
  • 4