如何在没有索引的情况下在 Python 中显示 Pandas Dataframe?
使用index=False忽略索引。让我们首先导入所需的库-
import pandas as pd
创建一个数据帧-
dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b'])
通过使用loc传递标签来选择行-
dataFrame.loc['x']
显示没有索引的DataFrame-
dataFrame.to_string(index=False)
示例
以下是代码-
import pandas as pd #创建数据帧 dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b']) #数据框 print"Displaying DataFrame with index...\n",dataFrame #用loc选择行 print"\nSelect rows by passing label..." print(dataFrame.loc['x']) #显示没有索引的DataFrame print"\nDisplaying DataFrame without Index...\n",dataFrame.to_string(index=False)输出结果
这将产生以下输出-
Displaying DataFrame with index...
a b
x 10 15
y 20 25
z 30 35
Select rows by passing label...
a 10
b 15
Name: x, dtype: int64
Displaying DataFrame without Index...
a b
10 15
20 25
30 35热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下