read_csv不分隔给定txt文件中的列

时间:2019-06-24 01:31:07

标签: pandas

我的输入txt文件如下所示:

2019-06-23 17:53                                                  Page 1


1.9752838,1.9752001,1.9752001,1.9749992,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017,1.9752017
1.9752017,1.9752017,1.9752017,1.9752017,1.9752989,1.9752471,1.9751560,1.9751560,1.9753192,1.9752765,1.9752767,1.9644918
1.9754473,1.9751872,1.9751872,1.9745865,1.9753944,1.9753007,1.9750204,1.9750204,1.9754550,1.9754478,1.9754481,1.9518886
1.9753613,1.9751965,1.9751965,1.9747815,1.9754874,1.9753416,1.9747925,1.9747925,1.9755443,1.9756079,1.9756084,1.9574568
1.9752838,1.9752001,1.9752001,1.9754132,1.9752989,1.9752471,1.9751559,1.9751560,1.9750417,1.9752768,1.9752767,1.9816657
1.9754473,1.9751873,1.9751873,1.9758274,1.9753945,1.9753007,1.9750204,1.9750204,1.9749107,1.9754483,1.9754481,1.9861361
1.9753612,1.9751966,1.9751966,1.9756361,1.9754875,1.9753416,1.9747925,1.9747926,1.9746301,1.9756088,1.9756084,1.9894820

当我这样做

df = pd.read_csv('/Users/jan/data/ofile.csv', sep = ",")

输出数据帧具有按照人们期望的方式组织的所有值,除了所有值都位于一列中,这由以下命令确认。

len(df.columns) 
1

如何使数据框看到列?我试着玩弄'header'标记,并将其读取为txt文件而不是csv,但没有任何方法可以解决问题。我知道以前曾多次问过这个问题,但似乎没有什么能解决我的问题。

1 个答案:

答案 0 :(得分:1)

使用class Users(UserMixin, db.Model): __tablename__ = 'users' id = db.Column(db.Integer(), primary_key=True) firstname = db.Column(db.String(100)) lastname = db.Column(db.String(100)) email = db.Column(db.String(120), unique=True) telephone = db.Column(db.String(15)) fullname = db.Column(db.String(100)) address1 = db.Column(db.String(100)) city = db.Column(db.String(50)) country = db.Column(db.String(50)) region = db.Column(db.String(50))

进行检查
user_info = {
    'firstname': 'Test1', 
    'lastname': 'Test2', 
    'telephone': '1234567890', 
    'city': 'City 1', 
    'email': 'example@gmail.com', 
    'address1': 'Address', 
    'country': 'America', 
    'region': 'Whatever'
}