2017-01-04 2 views
0

У меня проблема с использованием библиотеки python Seaborn. Это мой код:seaborn jointplot TypeError: строковые индексы должны быть целыми числами

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

Вывод мой код ошибки:

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

Что случилось с моим кодом? Использование других данных отлично!

BR МЛ

+0

Это была моя опечатка в имени расходов колонке. – Figlio

ответ

1

Оказывается, у вас есть простая проблема синтаксиса в коде:

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

И это будет работать нормально!

enter image description here

+0

Да, спасибо, я тоже видел :( – Figlio

Смежные вопросы