大熊猫[]中没有一个在索引中[重复]
python 230
原文标题 :pandas None of [] are in the index [duplicate]
如果维度匹配,可以将列表或 numpy 数组解压缩为多个变量。对于 3xN 阵列,以下将起作用:
import numpy as np
a,b = [[1,2,3],[4,5,6]]
a,b = np.array([[1,2,3],[4,5,6]])
# result: a=[1,2,3], b=[4,5,6]
如何为 pandasDataFrame
的列实现类似的行为?扩展上面的例子:
import pandas as pd
df = pd.DataFrame([[1,2,3],[4,5,6]])
df.columns = ['A','B','C'] # Rename cols and
df.index = ['i', 'ii'] # rows for clarity
以下不按预期工作:
a,b = df.T
# result: a='i', b='ii'
a,b,c = df
# result: a='A', b='B', c='C'
但是,我想得到的是以下内容:
a,b,c = unpack(df)
result: a=df['A'], b=df['B'], c=df['C']
功能unpack
已经在 pandas 中可用了吗?或者它可以以简单的方式被模仿吗?