Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Wrong parsing when importing csv file in python


I am trying to import a csv format file. this is tick trading data info. The file is as follows:

0,2017-09-18 02:00:06,12568.00,1,201,12567.00,12568.00,5462,0,0,C, 0,2017-09-18 02:00:06,12568.50,2,203,12567.00,12568.00,5463,0,0,C, 0,2017-09-18 02:00:06,12569.00,1,204,12567.00,12569.00,5468,0,0,C, 0,2017-09-18 02:00:06,12569.00,1,205,12567.00,12569.00,5470,0,0,C, 0,2017-09-18 02:00:06,12569.50,3,208,12567.00,12569.00,5471,0,0,C,

I am using this Python code:

import pandas as pd
df = pd.read_csv("XG#/20170918.txt", names=['empty', 'date time', 'last', 'last size', 'bid', 'ask'])

my output is this:

empty date time last \ 0 2017-09-18 02:00:06 12567.0 200.0 200.0 12567.0 12567.0 5430.0 0.0

last size bid ask 0 2017-09-18 02:00:06 12567.0 200.0 200.0 12567.0 0.0 C NaN

Process finished with exit code 0

My questions are: 1. why my "names" (headers) are not starting on the first column? 2. how do I make 2nd Column as date-time and index? 3. how do I widen the result so I will see all the data in one line (I am using pycharm)? 4. since I need to make date-time as index, I need to remove column 0 but when using df.drop(df.index[0]) nothing happens.

Any help is welcome!

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Wrong parsing when importing csv file in python


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription