Skip to main content
 首页 » 编程设计

python之Pandas 中的列名 (Python)

2024年09月07日12lonelyxmas

Python:Pandas:数据框:列名

我有很多列,列名也很大。我希望看到很少的列和行,但 View 变得受限于列名的大小。如何在没有列名的情况下临时在 Python 中查看数据框(仅显示数据)

请您参考如下方法:

将 DataFrame 转换为 numpy 数组:

print (df.values) 

但也许这里可以先按位置选择列的值 iloc :

print (df.iloc[:, 5:8].values) 

示例:

df = pd.DataFrame(np.random.randint(10, size=(3,10))) 
print (df) 
   0  1  2  3  4  5  6  7  8  9 
0  8  4  9  1  3  7  6  3  0  3 
1  3  2  6  8  9  3  7  5  7  4 
2  0  0  7  5  7  3  9  3  9  3 
 
print (df.iloc[:, 5:8]) 
   5  6  7 
0  7  6  3 
1  3  7  5 
2  3  9  3 
 
print (df.iloc[:, 5:8].values) 
[[7 6 3] 
 [3 7 5] 
 [3 9 3]]