Python 熊猫:数据文件中没有列名

Python 熊猫:数据文件中没有列名,python,python-2.7,numpy,pandas,Python,Python 2.7,Numpy,Pandas,我正在尝试处理一个数据集,用于数据科学,但它没有列名。df.head()的输出如下图所示: 1 73 Not in universe 0 0.1 0.2 Not in universe.1 0 2 58 Self-employed-not incorporated 4 34 0 Not in universe 1 3 18 Not in universe 0 0

我正在尝试处理一个数据集,用于数据科学,但它没有列名。
df.head()
的输出如下图所示:

   1  73                  Not in universe   0  0.1   0.2  Not in universe.1
0  2  58   Self-employed-not incorporated   4   34     0    Not in universe
1  3  18                  Not in universe   0    0     0        High school
2  4   9                  Not in universe   0    0     0    Not in universe
3  5  10                  Not in universe   0    0     0    Not in universe
4  6  48                          Private  40   10  1200    Not in universe
我想看到的是

0  1  73                  Not in universe   0  0.1   0.2  Not in universe.1
1  2  58   Self-employed-not incorporated   4   34     0    Not in universe
2  3  18                  Not in universe   0    0     0        High school
3  4   9                  Not in universe   0    0     0    Not in universe
4  5  10                  Not in universe   0    0     0    Not in universe
5  6  48                          Private  40   10  1200    Not in universe

我可以随机分配列名,但有更好的方法吗?

您加载文件时没有指定是否有标题行,默认情况下,它从第一行推断,如果缺少,则传递
header=None

df = pd.read_csv(file_path, header=None)

我想让你通过。标头的默认值为“推断”,这意味着如果未指定,它将自动设置数据的整数值

您还可以通过设置names参数来设置不同的列名,该参数采用数组、列名列表