【发布时间】:2019-08-09 03:16:48
【问题描述】:
我有一个包含许多分类变量的数据集,我想在散点图中绘制这些变量,而不必对变量进行编码。 这是我的尝试:
fig = plt.figure(figsize=(18, 9))
for column in df:
if df[column].dtype != np.int64 and df[column].dtype != np.float64:
ca = df.plot.scatter(x=df[column],y= df['log_prices'], ax =
fig.add_subplot(2,3,df[column]+1))
plt.plot(df.iloc[:,df[column]].values, sm.OLS(df.iloc
[:,df['log_prices'].values,sm.add_constant(df.iloc[:,df[column]].values)).fit().fittedvalues,'r-')
这是我目前遇到的错误:
----> 5 ca = df.plot.scatter(x=df[column],y=df['log_prices'], ax = fig.add_subplot(2,3,df_061[column]+1))
cannot concatenate 'str' and 'int' objects
这显然与 log_prices 有关。
有没有更简单的方法?
谢谢
【问题讨论】:
-
一方面,你可以跳过循环,使用pandas内置的
select_dtypes函数,即just greatIMO
标签: python pandas loops matplotlib graph