enter image description here我正在尝试在sqlite3中写入数据帧,运行数据库中创建的代码表并且所有列的数据均未写入。
gd.set_with_dataframe(wks,df[(df['Haus/Wohnung'] == k) & (df['Miete/Kauf'] == w)])
df = pd.DataFrame(df[(df['Haus/Wohnung'] == k) & (df['Miete/Kauf'] == w)])
df.to_sql('scraped_data1', con=engine, if_exists='replace')
错误
Traceback (most recent call last):
File "C:\python3.7\lib\site-packages\pandas\io\sql.py", line 616, in insert_data
temp.reset_index(inplace=True)
File "C:\python3.7\lib\site-packages\pandas\core\frame.py", line 4431, in reset_index
new_obj.insert(0, name, level_values)
File "C:\python3.7\lib\site-packages\pandas\core\frame.py", line 3473, in insert
allow_duplicates=allow_duplicates)
File "C:\python3.7\lib\site-packages\pandas\core\internals\managers.py", line 1149, in insert
raise ValueError('cannot insert {}, already exists'.format(item))
ValueError: cannot insert ID, already exists
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Shahr/Documents/test/modification.py", line 268, in <module>
cln.Scrap_data()
File "C:/Users/Shahr/Documents/test/modification.py", line 263, in Scrap_data
df.to_sql('scraped_data1', con=engine, if_exists='replace')
File "C:\python3.7\lib\site-packages\pandas\core\generic.py", line 2531, in to_sql
dtype=dtype, method=method)
File "C:\python3.7\lib\site-packages\pandas\io\sql.py", line 460, in to_sql
chunksize=chunksize, dtype=dtype, method=method)
File "C:\python3.7\lib\site-packages\pandas\io\sql.py", line 1174, in to_sql
table.insert(chunksize, method=method)
File "C:\python3.7\lib\site-packages\pandas\io\sql.py", line 664, in insert
keys, data_list = self.insert_data()
File "C:\python3.7\lib\site-packages\pandas\io\sql.py", line 619, in insert_data
"duplicate name in index/columns: {0}".format(err))
ValueError: duplicate name in index/columns: cannot insert ID, already exists
Process finished with exit code 1
添加“ index = False”后
Traceback (most recent call last):
cursor, statement, parameters, context
File "C:\python3.7\lib\site-packages\sqlalchemy\engine\default.py", line 547, in do_executemany
cursor.executemany(statement, parameters)
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 21 - probably unsupported type.
[SQL: INSERT INTO scraped_data1 ("Haus/Wohnung", "ID", "Miete/Kauf", address, balcony, "builtInKitchen", city, floorplan, "from", garden, lat, "livingSpace", lon, miete, "numberOfRooms", postcode, price, "privateOffer", quarter, title, url, xml) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (('Wohnung', '109546516', 'Kauf', 'Bosestraße 9, Mitte-Nord, Zwickau', 'true', 'false', 'Zwickau', 'true', '001.2293386', 'false', 50.72138, 103.34, 12.49098, ' 500 € ', 4, '08056', 80000, 'false', 'Mitte-Nord', 'Eigennutzer aufgepasst! Attraktive 4R-Maisonette im DG mit Balkon, Küche+Bad mit Fenster', 'https://www.immobilienscout24.de/expose/109546516', [<dd class="is24qa-typ grid-item three-fifths"> Maisonette </dd>, <dd class="is24qa-etage grid-item three-fifths"> 4 von 4 </dd>, <dd class="is24qa-wo ... (1820 characters truncated) ... "is24qa-endenergieverbrauch grid-item three-fifths"> 98,9 kWh/(m²*a) </dd>, <dd class="is24qa-energieeffizienzklasse grid-item three-fifths"> C </dd>]), ('Wohnung', '100540745', 'Kauf', 'Karl-Bartelmann-Straße 43, Böhlen, Leipzig (Kreis)', 'false', 'false', 'Leipzig (Kreis)', 'true', '001.185949', 'false', 51.19677, 41.42, 12.3852, ' 207 € ', 2, '04564', 45800, 'false', 'Böhlen', 'Über 5 % Rendite! Provisionsfreies, modernes Investment in gepflegter Anlage.', 'https://www.immobilienscout24.de/expose/100540745', [<dd class="is24qa-typ grid-item three-fifths"> Erdgeschosswohnung </dd>, <dd class="is24qa-etage grid-item three-fifths"> 0 von 2 </dd>, <dd class="i ... (1733 characters truncated) ... s="is24qa-endenergieverbrauch grid-item three-fifths"> 90 kWh/(m²*a) </dd>, <dd class="is24qa-energieeffizienzklasse grid-item three-fifths"> C </dd>]), ('Wohnung', '112517004', 'Kauf', 'Stötteritz, Leipzig', 'true', 'true', 'Leipzig', 'true', '001.4178540', 'false', None, 67.86, None, {}, 3, '04299', 155000, 'false', 'Stötteritz', 'Wunderschöne Maisonette mit Dachterrasse, Fußbodenheizung, Parkett und vielem mehr!', 'https://www.immobilienscout24.de/expose/112517004', [<dd class="is24qa-typ grid-item three-fifths"> Maisonette </dd>, <dd class="is24qa-etage grid-item three-fifths"> 4 von 5 </dd>, <dd class="is24qa-wo ... (1830 characters truncated) ... 4qa-energieausweistyp grid-item three-fifths"> Bedarfsausweis </dd>, <dd class="is24qa-endenergiebedarf grid-item three-fifths"> 153 kWh/(m²*a) </dd>]), ('Wohnung', '110665650', 'Kauf', 'Hermann-Kellner-Straße 12, Weißenborn, Zwickau', 'true', 'false', 'Zwickau', 'true', '001.2293386', 'false', 50.7387, 51, 12.46019, ' 343 € ', 2, '08058', 87000, 'false', 'Weißenborn', 'Weißenborn! Attraktive Zwei-Raum-Wohnung am Stadtwald, Küche mit Fenster, Balkon, TG-Stellplatz', 'https://www.immobilienscout24.de/expose/110665650', [<dd class="is24qa-etage grid-item three-fifths"> 2 von 3 </dd>, <dd class="is24qa-wohnflaeche-ca grid-item three-fifths"> 51 m² </dd>, <dd class="is2 ... (1758 characters truncated) ... nergieausweistyp grid-item three-fifths"> Verbrauchsausweis </dd>, <dd class="is24qa-endenergieverbrauch grid-item three-fifths"> 90 kWh/(m²*a) </dd>]), ('Wohnung', '110385692', 'Kauf', 'Reichenbacher Straße 33, Mitte-West, Zwickau', 'false', 'false', 'Zwickau', 'true', '001.2293386', 'false', 50.71546, 175, 12.48405, ' 795 € ', 5, '08056', 152000, 'false', 'Mitte-West', 'Herrliche 5-Raum-Wohnung im Erdgeschoss, Stellplatz, Denkmalschutz, Nähe Zentrum und Schwanenteich', 'https://www.immobilienscout24.de/expose/110385692', [<dd class="is24qa-etage grid-item three-fifths"> 0 von 4 </dd>, <dd class="is24qa-wohnflaeche-ca grid-item three-fifths"> 175 m² </dd>, <dd class="is ... (1658 characters truncated) ... "is24qa-endenergieverbrauch grid-item three-fifths"> 97,4 kWh/(m²*a) </dd>, <dd class="is24qa-energieeffizienzklasse grid-item three-fifths"> C </dd>]), ('Wohnung', '105772592', 'Kauf', 'Bühlau/Weißer Hirsch, Dresden', 'true', 'true', 'Dresden', 'true', '001.15660', 'false', None, 149.59, None, ' 1.040 € ', 4, '01324', 449000, 'false', 'Bühlau/Weißer Hirsch', 'Etagenwohnung mit 4 Zimmern in Loschwitz - ab September frei', 'https://www.immobilienscout24.de/expose/105772592', [<dd class="is24qa-typ grid-item three-fifths"> Etagenwohnung </dd>, <dd class="is24qa-etage grid-item three-fifths"> 1 von 3 </dd>, <dd class="is24qa ... (1937 characters truncated) ... usweistyp grid-item three-fifths"> Verbrauchsausweis </dd>, <dd class="is24qa-energieverbrauchskennwert grid-item three-fifths"> 162 kWh/(m²*a) </dd>]), ('Wohnung', '112391877', 'Kauf', 'Rabenau, Sächsische Schweiz-Osterzgebirge (Kreis)', 'true', 'false', 'Sächsische Schweiz-Osterzgebirge (Kreis)', 'true', '001.1246558', 'false', None, 72.67, None, ' 375 € ', 2, '01734', 92500, 'false', 'Rabenau', 'Provisionsfrei - Romantische Galeriewohnung mit Blick über das Ost-Erzgebirge als Kapitalanlage', 'https://www.immobilienscout24.de/expose/112391877', [<dd class="is24qa-typ grid-item three-fifths"> Dachgeschoss </dd>, <dd class="is24qa-wohnflaeche-ca grid-item three-fifths"> 72,67 m² </dd>, <dd clas ... (1529 characters truncated) ... ="is24qa-endenergieverbrauch grid-item three-fifths"> 118 kWh/(m²*a) </dd>, <dd class="is24qa-energieeffizienzklasse grid-item three-fifths"> D </dd>]), ('Wohnung', '110726412', 'Kauf', 'Berchtesgadener Straße 49, Laubegast, Dresden', 'true', 'false', 'Dresden', 'true', '001.4166441', 'true', 51.02597, 88.67, 13.82393, ' 583,27 € ', 4, '01279', 158050, 'false', 'Laubegast', 'Faires Angebot für Anleger und Eigennutzer!! 2 Apartments auf einer Etage-Einzelkauf a. Anfrage', 'https://www.immobilienscout24.de/expose/110726412', [<dd class="is24qa-typ grid-item three-fifths"> Etagenwohnung </dd>, <dd class="is24qa-etage grid-item three-fifths"> 2 von 4 </dd>, <dd class="is24qa ... (1945 characters truncated) ... nergieausweistyp grid-item three-fifths"> Verbrauchsausweis </dd>, <dd class="is24qa-endenergieverbrauch grid-item three-fifths"> 83 kWh/(m²*a) </dd>]) ... displaying 10 of 20 total bound parameter sets ... ('Wohnung', '111976694', 'Kauf', 'Böhlitz-Ehrenberg, Leipzig', 'true', 'false', 'Leipzig', 'true', '002.01002863916', 'false', None, 81, None, {}, 3, '04178', 140000, 'false', 'Böhlitz-Ehrenberg', 'Ihr Renditeobjekt in Top-Lage! // Vermietete 3-Zimmer-Whg. mit Balkon & Garage', 'https://www.immobilienscout24.de/expose/111976694', [<dd class="is24qa-typ grid-item three-fifths"> Hochparterre </dd>, <dd class="is24qa-wohnflaeche-ca grid-item three-fifths"> 81 m² </dd>, <dd class=" ... (1819 characters truncated) ... is24qa-endenergieverbrauch grid-item three-fifths"> 106,7 kWh/(m²*a) </dd>, <dd class="is24qa-energieeffizienzklasse grid-item three-fifths"> D </dd>]), ('Wohnung', '111593044', 'Kauf', 'Radebeul, Meißen (Kreis)', 'true', 'false', 'Meißen (Kreis)', 'true', '001.878285', 'true', None, 170, None, {}, 5, '01445', 539000, 'false', 'Radebeul', 'Großzügige Wohnung im historischen Denkmal!', 'https://www.immobilienscout24.de/expose/111593044', [<dd class="is24qa-typ grid-item three-fifths"> Sonstige </dd>, <dd class="is24qa-wohnflaeche-ca grid-item three-fifths"> 170 m² </dd>, <dd class="is2 ... (978 characters truncated) ... class="is24qa-heizungsart grid-item three-fifths"> Gas-Heizung </dd>, <dd class="is24qa-wesentliche-energietraeger grid-item three-fifths"> Gas </dd>]))]
(Background on this error at: http://sqlalche.me/e/rvf5)