2017-01-04 3 views
0

Ich habe ein Problem mit der Verwendung von Python Seaborn-Bibliothek. Dies ist mein Code:Seaborn Jointplot TypeError: String-Indizes müssen Ganzzahlen sein

#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') 

Ausgabe von meinem Code ist Fehler:

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

Was mit meinem Code falsch? Mit anderen Daten funktioniert gut!

BR mls

+0

Es war mein im Namen der Spalte Ausgaben Tippfehler. – Figlio

Antwort

1

Es scheint Ihnen eine einfache Syntax Problem in Ihrem Code haben:

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

Und es wird gut funktionieren!

enter image description here

+0

Ja, danke, ich sah auch :( – Figlio

Verwandte Themen