小编evo*_*olk的帖子

pgf/tikz:字符串符号作为输入坐标

我是pgf的新手所以我正在尝试pgfplot手册中的一些例子.一个例子与我当前的任务特别相关,但是,它不会编译.

这是代码:

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture} 
    \begin{axis}[symbolic x coords={a,b,c,d,e,f,g,h,i}] 
        \addplot+[smooth] coordinates { 
            (a,42) 
            (b,50) 
            (c,80) 
            (f,60) 
            (g,62) 
            (i,90)}; 
    \end{axis} 
\end{tikzpicture} 
\end{document}
Run Code Online (Sandbox Code Playgroud)

编译器退出时出现以下错误:

! Package PGF Math Error: Could not parse input 'a' as a floating point number,
 sorry. The unreadable part was near 'a'..
Run Code Online (Sandbox Code Playgroud)

我不知道如何纠正这种行为.其他图(平滑,散点图,条形图),只包含数值数据编译.

有人可以给我一个暗示吗?

干杯

K.

string plot axis tikz pgf

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

Pandas - 使用索引中的成对组合将数据帧转换为方阵

我正在将数据框转换为方阵。数据框有一个索引,并且只有一列带有浮点数。我需要做的是计算所有索引对,并为每对取两个关联列值的平均值。因此,通常的主元函数只是解决方案的一部分。

目前,该函数的估计复杂度为 O(n^2),这并不好,因为我必须处理一次包含数百行数据帧的较大输入。我可以采取另一种更快的方法吗?

输入示例(为简单起见,此处使用整数):

df = pd.DataFrame([3, 4, 5])
Run Code Online (Sandbox Code Playgroud)

更新:转换逻辑

对于示例中的输入数据框:

   0

0  3
1  4
2  5
Run Code Online (Sandbox Code Playgroud)

我执行以下操作(但并不声称这是最好的方法):

  • 获取所有索引对:(0,1), (1,2), (0,2)
  • 对于每一对,计算其值的平均值:(0,1):3.5、(1,2):4.5、(0,2):4.0
  • 使用每对中的索引作为列和行标识符以及对角线上的零来构建对称方阵(如所需输出所示)。

代码位于turn_table_into_square_matrix()中。

期望的输出:

    0   1   2

0   0.0 3.5 4.0
1   3.5 0.0 4.5
2   4.0 4.5 0.0
Run Code Online (Sandbox Code Playgroud)

目前的实施:

import pandas as pd
from itertools import combinations 
import time
import string
import random


def turn_table_into_square_matrix(original_dataframe):

    # get all pairs of indices 
    index_pairs = list(combinations(list(original_dataframe.index),2))

    rows_for_final_dataframe = []

    # collect new data frame row by row - the …
Run Code Online (Sandbox Code Playgroud)

python optimization pandas

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

标签 统计

axis ×1

optimization ×1

pandas ×1

pgf ×1

plot ×1

python ×1

string ×1

tikz ×1