cvs数据截图如下
设置index_col=0,目的是设置第一列name为index(索引),方便下面示例演示
data = pandas.read_csv(input1, index_col=0)
输出结果
price o_price date quan
name
wood 85.00 49.99 2006 797
chair 102.50 49.99 2006 799
bed 77.00 49.99 2006 795
lamp 162.50 49.99 2006 800
sofa 699.99 269.99 2002 3094
table 602.00 269.99 2002 3093
data[['o_price', 'quan']
# 或者
data.loc[:, ['o_price', 'quan']
输出结果
o_price quan
name
wood 49.99 797
chair 49.99 799
bed 49.99 795
lamp 49.99 800
sofa 269.99 3094
table 269.99 3093
data.iloc[:, [3, 4]]
输出结果
date quan
name
wood 2006 797
chair 2006 799
bed 2006 795
lamp 2006 800
sofa 2002 3094
table 2002 3093
data.loc[['wood', 'sofa'], :]
输出结果
price o_price date quan
name
wood 85.00 49.99 2006 797
sofa 699.99 269.99 2002 3094
data.iloc[[0, 1], :]
输出结果
price o_price date quan
name
wood 85.0 49.99 2006 797
chair 102.5 49.99 2006 799
loc是根据dataframe的具体标签选取列,而iloc是根据标签所在的位置,从0开始计数。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有