Python:Pandas在读取表格文本文件时不会分隔列

时间:2018-09-06 20:34:20

标签: python pandas dataframe multiple-columns

我有一个像这样的文本文件:

PERSONAL INFORMATION              

 First Name:             Michael
 Last Name:              Junior
 Birth Date:             May 17, 1999 
 Location:               Whitehurst Hall 301. City: Stillwater. State: OK
                         Taken on July 8, 2000 10:50:30 AM MST

WORK EXPERIENCE
Work type select                                        Part-time
ID number                                               10124
Company name                                            ABCDFG Inc.
Positions                                               Software Engineer/Research Scientist
                                                        Data Analyst/Scientist

您会看到第一列是要素名称,第二列是值。我是使用以下代码阅读的:

import pandas as pd
import numpy as np
import scipy as sp


df=pd.read_table('personal.txt',skiprows=1)
pd.set_option('display.max_colwidth',10000)
pd.set_option('display.max_rows',1000)
df

但是它合并了列和输出:

    PERSONAL INFORMATION
0   First Name: Michael
1   Last Name: Junior
2   Birth Date: May 17, 1999
3   Location: Whitehurst Hall 301. City: Stillwater. State: OK
4   Taken on July 8, 2000 10:50:30 AM MST
5   WORK EXPERIENCE
6   Work type select Part-time
7   ID number 10124
8   Company name Google Inc.
9   Positions Software Engineer/Research Scientist
10  Data Analyst/Scientist

我也应该摆脱这些标题的“个人信息”和“工作经验”。如何以一种能使我在两列中得到适当结果的方式阅读?

0 个答案:

没有答案