簡體   English   中英

seaborn jointplot TypeError:字符串索引必須為整數

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

我在使用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追溯(最近一次通話最后一次)----> 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(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-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#查找變量的名稱

TypeError:字符串索引必須是整數

我的代碼有什么問題? 使用其他數據很好!

BR毫升

看來您的代碼中有一個簡單的語法問題:

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

它將正常工作!

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM