You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Pandas DataFrame的行索引与列标签?

How to Print Pandas DataFrame Without Index and Column Labels

Hey there! Let's get your Pandas DataFrame to output just the raw data—no row indices or column labels included. Here are a few simple, effective methods to achieve exactly what you're looking for:

Method 1: Use to_string() with custom parameters

The to_string() method lets you customize how your DataFrame is printed. By setting index=False and header=False, you'll suppress both the row indices and column labels entirely:

import pandas as pd
l = [[1,2,3],[4,5,6],[7,8,9]]
New_dataframe = pd.DataFrame(l)
# Print without index and headers
print(New_dataframe.to_string(index=False, header=False))

This will output exactly the format you want:

1 2 3
4 5 6
7 8 9

Method 2: Use to_csv() for space-separated output

If you prefer a CSV-style approach (with spaces as separators), you can use to_csv() and disable indices/headers to get clean, unlabeled data:

print(New_dataframe.to_csv(sep=' ', index=False, header=False))

This produces the same clean output as above. Note: This method adds a trailing newline, but it's usually negligible for most use cases.

Method 3: Manual row iteration (for full control)

If you want complete control over how each line is formatted, you can iterate over the DataFrame's values directly, convert each row to a string, and print it:

for row in New_dataframe.values:
    print(' '.join(map(str, row)))

This approach is great if you need to tweak formatting further—like changing separators or adding custom text to individual rows.


内容的提问来源于stack exchange,提问作者Shubham Kuse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:26:03