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的答案)是解释的第二个参数。