【问题标题】:seaborn jointplot TypeError: string indices must be integersseaborn jointplot TypeError:字符串索引必须是整数
【发布时间】:2017-05-18 15:43:19
【问题描述】:

我在使用 python Seaborn 库时遇到问题。这是我的代码:

#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(最近调用 最后)在() ----> 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,空间, dropna、xlim、ylim、joint_kws、marginal_kws、annot_kws、**kwargs) 第796章 第797章 --> 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章 1660
x = x[not_na] -> 1661 y = y[not_na] 1662 1663 # 求变量名

TypeError:字符串索引必须是整数

我的代码有什么问题?使用其他数据效果很好!

BR 毫升

【问题讨论】:

  • 支出列的名称是我的印刷错误。

标签: python pandas seaborn


【解决方案1】:

您的代码中似乎有一个简单的语法问题:

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

它会正常工作的!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-28
    • 2021-04-28
    • 2020-06-24
    • 2016-03-26
    • 2017-09-07
    • 2018-08-19
    • 2016-02-17
    相关资源
    最近更新 更多