小编AS_*_*ler的帖子

Pandas/Numpy 从数组列中获取矩阵

我有一个带有一列列表的熊猫数据框。

df:

    inputs
0   [1, 2, 3]
1   [4, 5, 6]
2   [7, 8, 9]
3   [10, 11, 12]
Run Code Online (Sandbox Code Playgroud)

我需要矩阵

array([[ 1,  2,  3],
      [ 4,  5,  6],
      [ 7,  8,  9],
      [10, 11, 12]])
Run Code Online (Sandbox Code Playgroud)

一个有效的方法来做到这一点?

注意:当我尝试df.inputs.as_matrix()输出时

array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=object)
Run Code Online (Sandbox Code Playgroud)

它有形状(4,),不(4,3)符合要求。

python pandas

7
推荐指数
1
解决办法
1516
查看次数

Seaborn 自动颜色选择

我正在使用seaborn 创建水平条形图。从这个例子来看,我是如何设置颜色的。

sns.set_color_codes("pastel")
sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b")
Run Code Online (Sandbox Code Playgroud)

因此,在此示例中,“总计”字段将具有来自“粉彩”调色板的颜色“b”(蓝色)。

我有大约 60 个不同的字段,并且我不想手动设置所有颜色。有没有办法让seaborn自动选择颜色(甚至调色板)?

就目前情况而言,我的计划是在一个周期中创建条形图

for field in fields:
    sns.set_color_codes(foo)
    sns.barplot(x=field, y="abbrev", data=crashes, label=field, color="bar")
Run Code Online (Sandbox Code Playgroud)

其中foobar是由seaborn以某种方式为我生成的。

python pandas seaborn

1
推荐指数
1
解决办法
2557
查看次数

标签 统计

pandas ×2

python ×2

seaborn ×1