Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫:如何逐个拆分标题名称和列?_Python_Pandas_Split - Fatal编程技术网

Python 熊猫:如何逐个拆分标题名称和列?

Python 熊猫:如何逐个拆分标题名称和列?,python,pandas,split,Python,Pandas,Split,如何按\t逐个拆分标题名和列 现在的情况是,将txt文件加载到pandas中会给出以下列名: Cust_id\tSex\tBMI\tChildren\tDistrict 我希望列为: Cust_id Sex BMI Children District C210 M 22.99 2 Manchester 也像这个: C210\tM\t22.99\t2\tManchester 我希望列为: Cust_id Sex BMI Children District C210 M 22.99 2 M

如何按
\t
逐个拆分标题名和列

现在的情况是,将txt文件加载到pandas中会给出以下列名:

Cust_id\tSex\tBMI\tChildren\tDistrict
我希望列为:

Cust_id Sex BMI Children District
C210 M 22.99 2 Manchester
也像这个:

C210\tM\t22.99\t2\tManchester
我希望列为:

Cust_id Sex BMI Children District
C210 M 22.99 2 Manchester
我尝试使用
split
功能修复它们,但失败:

df.split('\t')

有人能告诉我如何修复吗?

将文件加载到数据帧时,必须定义分隔符:

df = pd.read_csv('file_name', sep='\t')
读报纸总是值得的。
sep
参数(参见下面@n7d的答案)是解释的第二个参数。