简体   繁体   English

python pandas切片列

[英]python pandas slice column

I have a pandas data structure with a shape of (500, 19). 我有一个形状为(500,19)的pandas数据结构。

dataset1 = pandas.read_csv(url, sep = ";", header = 0)

How can I slice the data vertically? 如何垂直切片数据?

Example: 例:

1,2,3
4,5,6
7,8,9

dataset1['slicing function to get second column'] yields: dataset1['slicing function to get second column']产生:

2
5
8

Use iloc function but python counts from 0 , so for second column need 1 : 使用iloc函数但python从0计数,因此对于第二列需要1

print (df.iloc[:, 1])
0    2
1    5
2    8
Name: 1, dtype: int64

For range: 适用范围:

print (df.iloc[:, 0:3])
   0  1  2
0  1  2  3
1  4  5  6
2  7  8  9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM