小编Jer*_*ith的帖子

在C中传递子字符串

我昨晚花了很多时间调试这段代码.我有两个数据文本文件,都包含18000个字符.我想将这些18000分成两个子串,每个子串100个,这使得180次迭代.

棘手的是,在前180次迭代中,两个子串的大小都很好.在18次迭代之后,子串的大小为0.

两个文件都正确打开.我可以打印它们等等.我尝试以我能想到的所有可能方式分配子字符串,但到目前为止找不到解决方案.

int main(int argc, char const *argv[]) { 

    //Ive loaded two files into two strings buff1 and buff2 both size of 18000 chars
    //It works fine with small data example, I dunno why but eventually I have work with much more bigger data set
    //Id like to divide them into 100 char long pieces and do some stuff with that 

    char *substrA;      //substring for buff1
    char *substrB;      //substring for buff2

    substrA = malloc((wlen+1)*sizeof(char));        //word length wlen=100
    substrA = …
Run Code Online (Sandbox Code Playgroud)

c string substring

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

具有分层列的 Pandas 数据透视表

我需要创建一个数据透视表。我的数据框具有以下结构:

\n\n

数据结构

\n\n
print (df)\n  company team person project unit start   end  num\n0     ABC  Dev   John     pr1   BE  date  date    3\n1     ABC  Dev    Tim     pr1   FE  date  date    4\n2     ABC  Dev  James     pr2   FE  date  date    3\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

我尝试使用以下 pandas 函数:

\n\n
table = pd.pivot_table(df,\n                index=["company","team","person"],\n                columns=["project", \'unit\'],\n                values=["start","end","num"],\n                aggfunc={"start": np.min,\n                       "end": np.max ,\n                       "num": np.sum},\n                fill_value=0)\ntable.columns = table.columns.swaplevel(2, 0).swaplevel(1, 0)\n
Run Code Online (Sandbox Code Playgroud)\n\n

数据转换为以下数据透视表:

\n\n

枢

\n\n

我最终得到了想要的数据结果,但格式是一个问题。I\xe2\x80\x99d 喜欢数据帧采用以下格式:

\n\n

期望的我们的结果

\n\n

有没有办法使用 pandas 数据透视表功能将列转换为分层列?

\n

python pivot-table pandas

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

标签 统计

c ×1

pandas ×1

pivot-table ×1

python ×1

string ×1

substring ×1