Python CSV library returning 1 item instead of a list of items

FullCombatBeard

Im trying to use the CSV library to do some excel processing, but when I use the code posted below, row returns the entirety of data as 1 item, so row[0] returns the entire file and row[1] returns index out of range. Is there a way to make each row a list with each cell being an item? Making the final product a list of lists. I was thinking of using split everytime ther was a close bracket ']' . If needed I can post the excel file

Heres a sample of what some of the output looks like. This is all one item in the list:

['3600035671,"$13,668",8/11/2008,8/11/2013,,,2,4A,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,']
['3910435005,"$34,872",4/1/2010,10/8/2016,,,2,4A,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,']
['5720636344,"$1,726",8/30/2010,9/5/2011,,,3,6C,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,']
['15260473510,"-$1,026,580",7/22/2005,3/5/2008,,,6,1C2A,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,']


import csv    
csvfile = open('Invictus.csv', 'rU')
data = csv.reader(csvfile, dialect=csv.excel_tab)    
for char in data:
    char = filter(None, char)
    print char
Shaun

Assuming you are giving examples of your data above the line import csv, it looks like your data is comma delimited but you are setting up your CSV reader to expect tab delimited data (dialect=csv.excel_tab).

What happens if you change that line to:

data = csv.reader(csvfile, dialect=csv.excel)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Breadcrumb selector for list items with a list item beside

분류에서Dev

Storing items in a list for python

분류에서Dev

Listview replaces first item instead of creating new items

분류에서Dev

Google gson.toJson(List) returning response as string instead of array

분류에서Dev

python nested list on second item

분류에서Dev

How to create a list with formatted items using DOM instead on HTML concatenation?

분류에서Dev

how to yield a parsed item from one link with other parsed items from other links in the same item list

분류에서Dev

python: list element in CSV file

분류에서Dev

String from CSV to list - Python

분류에서Dev

Make a list out of items in a sublist of a multidimensional list (python)

분류에서Dev

How to quickly convert from items in a list of lists to list of dictionaries in python?

분류에서Dev

dynamically create items ons-list-item for a carousel in onsen.ui

분류에서Dev

NSArray Returning String Instead of Dictionary

분류에서Dev

How to recognise an item selection/click in navigation drawer list instead of using its position in android?

분류에서Dev

list of items containing more than one variable in python

분류에서Dev

Python how to strip a string from a string based on items in a list

분류에서Dev

Count occurrences of assorted items in a List in a Dictionary Value in Python

분류에서Dev

item_list [-1]! = item_list [-2]의 더 파이썬적인 방법?

분류에서Dev

Can the value of both the current and next item be accessed in a Python list comprehension?

분류에서Dev

Display sharepoint library items with Javascript

분류에서Dev

InnerHTML Append Item instead of Replace

분류에서Dev

Linq to sql query not returning correct items

분류에서Dev

Setting items from a list to another list (both containing class instances) in random groups in python

분류에서Dev

UITabBarItem은 무엇입니까 * item = [self.tabBar.items objectAtIndex : 1]; 신속하게?

분류에서Dev

c function returning nan instead of double

분류에서Dev

SelectedItem.Text returning selectedvalue instead

분류에서Dev

Weird issue with returning empty struct instead of NULL

분류에서Dev

MySQL returning the MIN id instead of the MAX id?

분류에서Dev

Search and list items in vector

Related 관련 기사

  1. 1

    Breadcrumb selector for list items with a list item beside

  2. 2

    Storing items in a list for python

  3. 3

    Listview replaces first item instead of creating new items

  4. 4

    Google gson.toJson(List) returning response as string instead of array

  5. 5

    python nested list on second item

  6. 6

    How to create a list with formatted items using DOM instead on HTML concatenation?

  7. 7

    how to yield a parsed item from one link with other parsed items from other links in the same item list

  8. 8

    python: list element in CSV file

  9. 9

    String from CSV to list - Python

  10. 10

    Make a list out of items in a sublist of a multidimensional list (python)

  11. 11

    How to quickly convert from items in a list of lists to list of dictionaries in python?

  12. 12

    dynamically create items ons-list-item for a carousel in onsen.ui

  13. 13

    NSArray Returning String Instead of Dictionary

  14. 14

    How to recognise an item selection/click in navigation drawer list instead of using its position in android?

  15. 15

    list of items containing more than one variable in python

  16. 16

    Python how to strip a string from a string based on items in a list

  17. 17

    Count occurrences of assorted items in a List in a Dictionary Value in Python

  18. 18

    item_list [-1]! = item_list [-2]의 더 파이썬적인 방법?

  19. 19

    Can the value of both the current and next item be accessed in a Python list comprehension?

  20. 20

    Display sharepoint library items with Javascript

  21. 21

    InnerHTML Append Item instead of Replace

  22. 22

    Linq to sql query not returning correct items

  23. 23

    Setting items from a list to another list (both containing class instances) in random groups in python

  24. 24

    UITabBarItem은 무엇입니까 * item = [self.tabBar.items objectAtIndex : 1]; 신속하게?

  25. 25

    c function returning nan instead of double

  26. 26

    SelectedItem.Text returning selectedvalue instead

  27. 27

    Weird issue with returning empty struct instead of NULL

  28. 28

    MySQL returning the MIN id instead of the MAX id?

  29. 29

    Search and list items in vector

뜨겁다태그

보관