python取数组第一个元素_Python Pandas:在所有单元格中选择数组中的第一个元素... - Go语言中文社区

python取数组第一个元素_Python Pandas:在所有单元格中选择数组中的第一个元素...


What I am trying to do is select the 1st element of each cell regardless of the number of columns or rows (they may change based on user defined criteria) and make a new pandas dataframe from the data. My actual data structure is similar to what I have listed below.

0 1 2

0 [1, 2] [2, 3] [3, 6]

1 [4, 2] [1, 4] [4, 6]

2 [1, 2] [2, 3] [3, 6]

3 [4, 2] [1, 4] [4, 6]

I want the new dataframe to look like:

0 1 2

0 1 2 3

1 4 1 4

2 1 2 3

3 4 1 4

The code below generates a data set similar to mine and attempts to do what I want to do in my code without success (d), and mimics what I have seen in a similar question with success(c ; however, only one column). The link to the similar, but different question is here :Python Pandas: selecting element in array column

import pandas as pd

zz = pd.DataFrame([[[1

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_39714383/article/details/111951265
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-28 22:57:27
  • 阅读 ( 773 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢