Figlio
Figlio

Reputation: 41

seaborn jointplot TypeError: string indices must be integers

I have problem with using python Seaborn library. This is my code:

#Importing main libraries
import pandas as pd
from pandas import Series,DataFrame
import numpy as np

# For Visualization
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline

url = 'https://d396qusza40orc.cloudfront.net/eureconometrics-assets/Dataset%20Files%20for%20On-Demand%20Course/Exercises%20and%20datasets/Module%201/TrainExer11.txt'

df2 = pd.read_csv(url,delim_whitespace=True)
df2.head()
df2.info()
#All columns types are int64
sns.jointplot('Age','Excenditures',data=df2,kind='scatter')

Output of my code is error:

TypeError Traceback (most recent call last) in () ----> 1 sns.jointplot('Age','Excenditures',data=df,kind='scatter')

C:\WinPython-32bit-3.5.2.2\python-3.5.2\lib\site-packages\seaborn\distributions.py in jointplot(x, y, data, kind, stat_func, color, size, ratio, space, dropna, xlim, ylim, joint_kws, marginal_kws, annot_kws, **kwargs) 796 grid = JointGrid(x, y, data, dropna=dropna, 797 size=size, ratio=ratio, space=space, --> 798 xlim=xlim, ylim=ylim) 799 800 # Plot the data using the grid

C:\WinPython-32bit-3.5.2.2\python-3.5.2\lib\site-packages\seaborn\axisgrid.py in init(self, x, y, data, size, ratio, space, dropna, xlim, ylim) 1659 not_na = pd.notnull(x) & pd.notnull(y) 1660
x = x[not_na] -> 1661 y = y[not_na] 1662 1663 # Find the names of the variables

TypeError: string indices must be integers

What's wrong with my code? Using other data works fine!

BR mls

Upvotes: 0

Views: 2057

Answers (1)

Fourier
Fourier

Reputation: 2983

It appears you have a simple syntax problem in your code:

sns.jointplot('Age','Expenditures',data=df2,kind='scatter')

And it will work fine!

enter image description here

Upvotes: 2

Related Questions