如何在没有索引的情况下在 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热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短