将数据框中的列表元素转换为熊猫列

时间:2018-07-12 20:53:58

标签: python list pandas

我有这个小问题。我有一个具有以下形状的数据框:

   var circleLayer = CALayer()

   override func viewDidLoad() {

       super.viewDidLoad()
       self.view.wantsLayer = true
       initializeCircleLayer()
       simpleCAAnimationDemo()
   }

   func initializeCircleLayer(){

       circleLayer.bounds = CGRect(x: 0, y: 0, width: 150, height: 150)
       circleLayer.position = CGPoint(x: 50, y: 150)
       circleLayer.backgroundColor = NSColor.red.cgColor
       circleLayer.cornerRadius = 10.0

       let testIm = NSImage(named: NSImage.Name(rawValue: "testImage"))
       print("testIm = \(String(describing: testIm))")

       circleLayer.contents = NSImage(named: NSImage.Name(rawValue:  "testImage"))?.cgImage
       circleLayer.contentsGravity = kCAGravityCenter

       self.view.layer?.addSublayer(circleLayer)
   }

   func simpleCAAnimationDemo(){

       circleLayer.removeAllAnimations()
       let animation = CABasicAnimation(keyPath: "position")
       let startingPoint = NSValue(point: NSPoint(x: 50, y: 150))
       let endingPoint = NSValue(point: NSPoint(x: 600, y: 150))
       animation.fromValue = startingPoint
       animation.toValue = endingPoint
       animation.repeatCount = Float.greatestFiniteMagnitude
       animation.duration = 10.0
       circleLayer.add(animation, forKey: "linearMovement")
   }

我想把它变成这样:

id    d
1   [1,2,3]
2   [4,5,6]

我尝试过:

id    d      v1  v2  v3
1   [1,2,3]   1   2   3
2   [4,5,6]   4   5   6

但是,这给了我以下内容:

for i in A['d']:
A['v1']=i[0]
A['v2']=i[1]
A['v3']=i[2]

(它将每行的最后一个列表的元素粘贴)。我确定我的错误很小,但是找不到。我究竟做错了什么? 预先感谢!

0 个答案:

没有答案