📌  相关文章
📜  如何使用没有标题的 Pandas 读取 csv 文件?

📅  最后修改于: 2022-05-13 01:54:28.906000             🧑  作者: Mango

如何使用没有标题的 Pandas 读取 csv 文件?

先决条件:熊猫

CSV 文件的标题是分配给每一列的值数组。它充当数据的行标题。本文讨论了如何使用 Pandas 读取没有标题的 csv 文件。为此,在读取文件时应将标头属性设置为 None。

句法:

方法

  • 导入模块
  • 读取文件
  • 将标题设置为无
  • 显示数据

让我们首先看看数据是如何与标题一起显示的,以使差异一目了然。



使用的数据文件:

  • 文件.csv
  • 样本.csv

示例 1:

Python3
# importing python package
import pandas as pd
  
# read the contents of csv file
dataset = pd.read_csv("file.csv")
  
# display the modified result
display(dataset)


Python3
# importing python package
import pandas as pd
  
# read the contents of csv file
dataset = pd.read_csv("file.csv", header=None)
  
# display the modified result
display(dataset)


Python3
# importing python package
import pandas as pd
  
# read the content of csv file
dataset = pd.read_csv("sample1.csv", header=None)
  
# display modified csv file
display(dataset)


输出:

现在让我们看看没有标题的实现。

示例 2:

蟒蛇3



# importing python package
import pandas as pd
  
# read the contents of csv file
dataset = pd.read_csv("file.csv", header=None)
  
# display the modified result
display(dataset)

输出:

示例 3:

蟒蛇3

# importing python package
import pandas as pd
  
# read the content of csv file
dataset = pd.read_csv("sample1.csv", header=None)
  
# display modified csv file
display(dataset)

输出: