简体   繁体   English

seaborn jointplot TypeError:字符串索引必须为整数

[英]seaborn jointplot TypeError: string indices must be integers

I have problem with using python Seaborn library. 我在使用python Seaborn库时遇到问题。 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') ()中的TypeError追溯(最近一次通话最后一次)----> 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 \\ distributions.py(x,y,数据,种类,stat_func,颜色,大小,比率,空间,dropna ,xlim,ylim,joint_kws,marginal_kws,annot_kws,** kwargs)796网格= JointGrid(x,y,data,dropna = dropna,797 size = size,ratio = ratio,space = space,-> 798 xlim = xlim ,ylim = ylim)799 800#使用网格绘制数据

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 C:\\ WinPython-32位-3.5.2.2 \\蟒-3.5.2 \\ lib中\\站点包\\ seaborn \\ axisgrid.py在初始化 (个体,X,Y,数据,尺寸,比率,空间,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 x = x [not_na]-> 1661 y = y [not_na] 1662 1663#查找变量的名称

TypeError: string indices must be integers TypeError:字符串索引必须是整数

What's wrong with my code? 我的代码有什么问题? Using other data works fine! 使用其他数据很好!

BR mls BR毫升

It appears you have a simple syntax problem in your code: 看来您的代码中有一个简单的语法问题:

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

And it will work fine! 它将正常工作!

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM