torcharrow.DataFrame.select¶
- DataFrame.select(*args, **kwargs)¶
类似于SQL的SELECT。
通过选择旧列和新(计算)列来转换数据框。
特殊符号 me 可以用来指代自己。
- Parameters:
args (位置字符串参数) – 要在投影中保留的列名。列名为“*”是表示所有列的快捷方式。以“-”开头的列名表示删除该列。
kwargs (命名值参数) – 要添加到投影中的新列名表达式
示例
>>> from torcharrow import ta >>> xf = ta.dataframe({ >>> 'A': ['a', 'b', 'a', 'b'], >>> 'B': [1, 2, 3, 4], >>> 'C': [10,11,12,13]}) >>> xf.select(*xf.columns,D=me['B']+me['C']) index A B C D ------- --- --- --- --- 0 a 1 10 11 1 b 2 11 13 2 a 3 12 15 3 b 4 13 17 dtype: Struct([Field('A', string), Field('B', int64), Field('C', int64), Field('D', int64)]), count: 4, null_count: 0
使用‘*’和‘-colname’:
>>> xf.select('*','-B',D=me['B']+me['C']) index A C D ------- --- --- --- 0 a 10 11 1 b 11 13 2 a 12 15 3 b 13 17 dtype: Struct([Field('A', string), Field('C', int64), Field('D', int64)]), count: 4, null_count: 0