Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't import csv data
#1
in the code below, page is the webpage response from Playwright for what it's worth:
The csv file gets created ok and looks good as far as I can tell. But then when I go to import this file into a Microsoft Access database, nothing is imported. Is there some sort of conversion that needs to be done before writing the data to the csv file?
Thank you

                for row in page.query_selector_all("table tbody tr"):
                    i += 1
                    link = row.query_selector("xpath=td/a[text()='View']")
                    url = link.get_attribute('href')
                    charges = process_details(url)
                    if charges not in ['', 'err']:
                        charges = fix_charge(charges)
                        print(charges)
                        for charge in charges.split(';'):
                            print('------', charge)
                            record = [
                                    row.query_selector_all("td")[1].inner_text(),
                                    row.query_selector_all("td")[2].inner_text(),
                                    row.query_selector_all("td")[3].inner_text(),
                                    row.query_selector_all("td")[4].inner_text(),
                                    row.query_selector_all("td")[6].inner_text(),
                                    charge.strip().replace(',', ';'),
                                    new_date
                            ]
                            if charge.strip() not in ['', ' ']:
                                output_file.writerow(record)
                page.go_back()
        file.close()


def fix_charge(charge):
    charge = charge[charge.index(' '):].lstrip()

    for num in re.findall('\d+', charge):
        charge = charge.replace(num, '1')
    charge = charge.replace('1.', ';')
    charge = charge.replace('1-', ';')
    charge = charge.replace('1)', ';')
    charge = charge.replace('(1)', ';')
    charge = charge.replace(' 1 ', ';')
    charge = charge.strip().strip(',')
    return charge.strip()
Reply
#2
(Sep-16-2022, 10:43 AM)JonWayn Wrote: The csv file gets created ok and looks good as far as I can tell.
Then why do you think there is problem with the created file? It looks there is problem with the import of csv file into Microsoft Access. This is the wrong forum to ask question about Microsoft Access.
That said, without sample csv file even if someone wants to test import into Microsoft Access, they cannot do so.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Sep-16-2022, 10:43 AM)JonWayn Wrote: But then when I go to import this file into a Microsoft Access database, nothing is imported.

It's been a number of years since I worked with MS Access, but from what I can recall: make sure that the separator is set to comma, and not some other separator. Also, I think I remember a setting that tells Access if the first row contains the header information. If not, the table will be created with default header names, which you can, of course, edit, post import.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#4
(Sep-16-2022, 11:01 AM)buran Wrote:
(Sep-16-2022, 10:43 AM)JonWayn Wrote: The csv file gets created ok and looks good as far as I can tell.
Then why do you think there is problem with the created file? It looks there is problem with the import of csv file into Microsoft Access. This is the wrong forum to ask question about Microsoft Access.
That said, without sample csv file even if someone wants to test import into Microsoft Access, they cannot do so.

I just wanted to clear out of the way and conversion issue
Reply
#5
(Sep-16-2022, 09:28 PM)rob101 Wrote:
(Sep-16-2022, 10:43 AM)JonWayn Wrote: But then when I go to import this file into a Microsoft Access database, nothing is imported.

It's been a number of years since I worked with MS Access, but from what I can recall: make sure that the separator is set to comma, and not some other separator. Also, I think I remember a setting that tells Access if the first row contains the header information. If not, the table will be created with default header names, which you can, of course, edit, post import.

As I found out later, the same file imports ok in another table. So I deleted and recreated the failed table, thinking there might have been some corruption to it. I also created a linked table to the file, using a query to get the records into the table. Still empty. So one table is behaving differently from the other. So it is starting to look like a problem in Access and not the file contents. And yes, Access has the feature to specify that first row is headers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 801 May-29-2023, 02:42 PM
Last Post: Nietzsche
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,665 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Python 3.11 data import question love0715 2 771 Mar-05-2023, 06:50 PM
Last Post: snippsat
  I try to import data from Excel table to Word Template. NewbiePyPy 0 3,216 Oct-21-2020, 12:25 PM
Last Post: NewbiePyPy
  Import CSV data into array and turn into integers DoctorSmiles 5 3,098 Jul-16-2020, 10:47 AM
Last Post: perfringo
  How to import data to excel jkessous 4 2,875 Jan-26-2020, 07:53 PM
Last Post: snippsat
  Early data import question VorpalPirate 2 2,221 Dec-09-2019, 10:52 PM
Last Post: snippsat
  How to import data from database to excel nick123 1 3,437 Oct-09-2019, 04:39 PM
Last Post: sm51251
  Import data from excel to Teradata steve87bg 3 4,701 Sep-18-2019, 01:36 PM
Last Post: steve87bg
  Import and/or read IMC measurement data Squipy 0 3,704 Aug-11-2019, 02:48 PM
Last Post: Squipy

Forum Jump:

User Panel Messages

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