Python Forum
problem writing dataframe to oracle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem writing dataframe to oracle
#1
i have a simple csv file as follows :

Output:
1,'sami' 2.'john', 3,'mary' 4,'peter'
and i have a table test(id, name)

the code is as follows minus DB connection details since connection is fine :

#df=pd.read_csv('test.csv',encoding= 'unicode_escape', header = None)
df=pd.read_csv('test.csv',encoding= 'unicode_escape' )
print(df)
df.shape
df.info()
df.to_sql('test', engine, index=False, if_exists='append')
[/python]

I am trying to load the csv using pandas data frames but if i dont put the header in csv as "id,name" it does not insert rows and throws "invalid identifier " error.
I want to load this csv file in the table without having to put a header .
please advise .The code and error are below.

Note: I have tried using header=None ,still doesnt work .
Note2: plz note that if I put the header Id,Name in the csv file the code works fine and loads the rows in the table.

see attached outputs for both cases , first one is without using the header clause and second case is using header clause.
Yoriz write Sep-25-2021, 12:45 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

.txt   run_with_header_none.txt (Size: 3.35 KB / Downloads: 218)
.txt   run_withhout_header_none.txt (Size: 3.35 KB / Downloads: 215)
Reply
#2
see: https://stackoverflow.com/a/47540978
Reply
#3
thanks but the link you posted has no relation to my issue. as I stated I don't have any issue in connection or loading as long as I keep the header . I want to know how to load the data when the csv file has no header
Reply
#4
to any moderator: I think the thing i am trying to do is very common and simple , i am facing issue because I am novice. So I am surprised why I am not getting response .
Did i post this in a wrong group ?
please advise
Reply
#5
I am not sure I understand. If I understand then I do not know what your database field names are but perhaps you just need to use something as in the following.

df=pd.read_csv('test.csv', names=["Id", "Name"])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Writing in a document problem IOHANNES 4 1,059 Oct-26-2022, 08:58 PM
Last Post: IOHANNES
  2-dataframe, datetime lookup problem Mark17 0 1,238 Jan-27-2022, 01:02 AM
Last Post: Mark17
  Problem in saving .xlsm (excel) file using pandas dataframe in python shantanu97 2 4,294 Aug-29-2021, 12:39 PM
Last Post: snippsat
  Dataframe problem stylingpat 3 2,821 Mar-22-2021, 10:36 AM
Last Post: stylingpat
  Problem with If statement and dataframe Milfredo 1 1,773 Sep-16-2020, 05:50 AM
Last Post: Milfredo
  optimization problem for dataframe manipulation fimmu 0 1,466 Aug-31-2020, 06:02 PM
Last Post: fimmu
  Dataframe mean calculation problem: do we have to loop? sparkt 1 2,177 Aug-28-2020, 02:41 PM
Last Post: sparkt
  Problem writing a variable value to Excel Chuck_Norwich 1 1,940 Jul-25-2019, 02:20 PM
Last Post: Chuck_Norwich
  Problem with reading and writing to file. darktitan 2 2,292 Jul-20-2019, 06:06 PM
Last Post: darktitan

Forum Jump:

User Panel Messages

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