Python Forum
csv import issue by newbee
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
csv import issue by newbee
#1
hi
i am trying to import a txt file but it's in csv format. this is tick trading data info.
the file is this:
Quote:0,2017-09-18 02:00:06,12567.00,200,200,12567.00,12567.00,5430,0,0,C,
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,
0,2017-09-18 02:00:06,12570.00,3,211,12567.00,12569.00,5472,0,0,C,

i am using the following code:
import pandas as pd
df = pd.read_csv("XG#/20170918.txt", names=['empty', 'date time', 'last', 'last size', 'bid', 'ask'])
print(df.head(1))
the file is imported but not as expected. the results is:
Output:
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" 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

thanks for your support and help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Possible Scikit-Learn Import Issue? BlackHeart 2 7,172 Oct-26-2017, 04:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020