{"id":74659,"date":"2022-05-17T22:17:29","date_gmt":"2022-05-18T02:17:29","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/?p=74659"},"modified":"2022-05-17T22:18:38","modified_gmt":"2022-05-18T02:18:38","slug":"python-and-mongodb-operations-code-example","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=74659","title":{"rendered":"Python and MongoDB Operations. Code Example"},"content":{"rendered":"\n<p>#!\/usr\/bin\/env python# coding: utf-8<br \/># In[63]:<\/p>\n\n\n\n<p>import pymongo;<\/p>\n\n\n\n<p># In[64]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)<br \/>mydb = myclient[&#8220;mydatabase&#8221;]<\/p>\n\n\n\n<p># In[65]:<\/p>\n\n\n\n<p># Check if database exist<\/p>\n\n\n\n<p># In[66]:<\/p>\n\n\n\n<p>print(myclient.list_database_names())<\/p>\n\n\n\n<p># In[67]:<\/p>\n\n\n\n<p>dblist = myclient.list_database_names()if &#8220;mydatabase&#8221; in dblist:&nbsp; print(&#8220;The database exists.&#8221;)<\/p>\n\n\n\n<p># In[68]:<\/p>\n\n\n\n<p># Create a collection<\/p>\n\n\n\n<p># In[69]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]<br \/>mycol = mydb[&#8220;customers&#8221;]<\/p>\n\n\n\n<p># In[70]:<\/p>\n\n\n\n<p>#collection exist<\/p>\n\n\n\n<p># In[71]:<\/p>\n\n\n\n<p>print(mydb.list_collection_names())<\/p>\n\n\n\n<p># In[72]:<\/p>\n\n\n\n<p>collist = mydb.list_collection_names()if &#8220;customers&#8221; in collist:&nbsp; print(&#8220;The collection exists.&#8221;)<\/p>\n\n\n\n<p># In[73]:<\/p>\n\n\n\n<p># Insert into collection<\/p>\n\n\n\n<p># In[74]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mydict = { &#8220;name&#8221;: &#8220;John&#8221;, &#8220;address&#8221;: &#8220;Highway 37&#8221; }<br \/>x = mycol.insert_one(mydict)<\/p>\n\n\n\n<p># In[75]:<\/p>\n\n\n\n<p># return id of the inserted record<\/p>\n\n\n\n<p># In[76]:<\/p>\n\n\n\n<p>mydict = { &#8220;name&#8221;: &#8220;Peter&#8221;, &#8220;address&#8221;: &#8220;Lowstreet 27&#8221; }x = mycol.insert_one(mydict)print(x.inserted_id)<\/p>\n\n\n\n<p># In[77]:<\/p>\n\n\n\n<p># How to insert multiple documents<\/p>\n\n\n\n<p># In[78]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mylist = [&nbsp; { &#8220;name&#8221;: &#8220;Amy&#8221;, &#8220;address&#8221;: &#8220;Apple st 652&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Hannah&#8221;, &#8220;address&#8221;: &#8220;Mountain 21&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Michael&#8221;, &#8220;address&#8221;: &#8220;Valley 345&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Sandy&#8221;, &#8220;address&#8221;: &#8220;Ocean blvd 2&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Betty&#8221;, &#8220;address&#8221;: &#8220;Green Grass 1&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Richard&#8221;, &#8220;address&#8221;: &#8220;Sky st 331&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Susan&#8221;, &#8220;address&#8221;: &#8220;One way 98&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Vicky&#8221;, &#8220;address&#8221;: &#8220;Yellow Garden 2&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Ben&#8221;, &#8220;address&#8221;: &#8220;Park Lane 38&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;William&#8221;, &#8220;address&#8221;: &#8220;Central st 954&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Chuck&#8221;, &#8220;address&#8221;: &#8220;Main Road 989&#8221;},&nbsp; { &#8220;name&#8221;: &#8220;Viola&#8221;, &#8220;address&#8221;: &#8220;Sideway 1633&#8221;}]<br \/>x = mycol.insert_many(mylist)<br \/>#print list of the _id values of the inserted documents:print(x.inserted_ids)<\/p>\n\n\n\n<p># In[79]:<\/p>\n\n\n\n<p>#insert many documents and also provide the id to each record\/document<\/p>\n\n\n\n<p># In[80]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mylist = [&nbsp; { &#8220;_id&#8221;: 1, &#8220;name&#8221;: &#8220;John&#8221;, &#8220;address&#8221;: &#8220;Highway 37&#8221;},&nbsp; { &#8220;_id&#8221;: 2, &#8220;name&#8221;: &#8220;Peter&#8221;, &#8220;address&#8221;: &#8220;Lowstreet 27&#8221;},&nbsp; { &#8220;_id&#8221;: 3, &#8220;name&#8221;: &#8220;Amy&#8221;, &#8220;address&#8221;: &#8220;Apple st 652&#8221;},&nbsp; { &#8220;_id&#8221;: 4, &#8220;name&#8221;: &#8220;Hannah&#8221;, &#8220;address&#8221;: &#8220;Mountain 21&#8221;},&nbsp; { &#8220;_id&#8221;: 5, &#8220;name&#8221;: &#8220;Michael&#8221;, &#8220;address&#8221;: &#8220;Valley 345&#8221;},&nbsp; { &#8220;_id&#8221;: 6, &#8220;name&#8221;: &#8220;Sandy&#8221;, &#8220;address&#8221;: &#8220;Ocean blvd 2&#8221;},&nbsp; { &#8220;_id&#8221;: 7, &#8220;name&#8221;: &#8220;Betty&#8221;, &#8220;address&#8221;: &#8220;Green Grass 1&#8221;},&nbsp; { &#8220;_id&#8221;: 8, &#8220;name&#8221;: &#8220;Richard&#8221;, &#8220;address&#8221;: &#8220;Sky st 331&#8221;},&nbsp; { &#8220;_id&#8221;: 9, &#8220;name&#8221;: &#8220;Susan&#8221;, &#8220;address&#8221;: &#8220;One way 98&#8221;},&nbsp; { &#8220;_id&#8221;: 10, &#8220;name&#8221;: &#8220;Vicky&#8221;, &#8220;address&#8221;: &#8220;Yellow Garden 2&#8221;},&nbsp; { &#8220;_id&#8221;: 11, &#8220;name&#8221;: &#8220;Ben&#8221;, &#8220;address&#8221;: &#8220;Park Lane 38&#8221;},&nbsp; { &#8220;_id&#8221;: 12, &#8220;name&#8221;: &#8220;William&#8221;, &#8220;address&#8221;: &#8220;Central st 954&#8221;},&nbsp; { &#8220;_id&#8221;: 13, &#8220;name&#8221;: &#8220;Chuck&#8221;, &#8220;address&#8221;: &#8220;Main Road 989&#8221;},&nbsp; { &#8220;_id&#8221;: 14, &#8220;name&#8221;: &#8220;Viola&#8221;, &#8220;address&#8221;: &#8220;Sideway 1633&#8221;}]<br \/>x = mycol.insert_many(mylist)<br \/>#print list of the _id values of the inserted documents:print(x.inserted_ids)<\/p>\n\n\n\n<p># In[81]:<\/p>\n\n\n\n<p># find one<\/p>\n\n\n\n<p># In[82]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>x = mycol.find_one()<br \/>print(x)<\/p>\n\n\n\n<p># In[83]:<\/p>\n\n\n\n<p># Select * i.e. find<\/p>\n\n\n\n<p># In[84]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>for x in mycol.find():&nbsp; print(x)<\/p>\n\n\n\n<p># In[23]:<\/p>\n\n\n\n<p># find some columns<\/p>\n\n\n\n<p># In[26]:<\/p>\n\n\n\n<p>import pymongo;<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;);mydb = myclient[&#8220;mydatabase&#8221;];mycol = mydb[&#8220;customers&#8221;];<br \/>for x in mycol.find({},{ &#8220;_id&#8221;: 0, &#8220;name&#8221;: 1, &#8220;address&#8221;: 1 }):&nbsp; print(x)<\/p>\n\n\n\n<p># In[27]:<\/p>\n\n\n\n<p># Exclude address from the result<\/p>\n\n\n\n<p># In[28]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>for x in mycol.find({},{ &#8220;address&#8221;: 0 }):&nbsp; print(x)<\/p>\n\n\n\n<p># In[29]:<\/p>\n\n\n\n<p>#error if both 0 and 1 in the same object<\/p>\n\n\n\n<p># In[30]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>for x in mycol.find({},{ &#8220;name&#8221;: 1, &#8220;address&#8221;: 0 }):&nbsp; print(x)<\/p>\n\n\n\n<p># In[31]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>for x in mycol.find({},{ &#8220;name&#8221;: 1 }):&nbsp; print(x)<\/p>\n\n\n\n<p># In[32]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: { &#8220;$gt&#8221;: &#8220;S&#8221; } }<br \/>mydoc = mycol.find(myquery)<br \/>for x in mydoc:&nbsp; print(x)<\/p>\n\n\n\n<p># In[33]:<\/p>\n\n\n\n<p># advanced query with regular expressions<\/p>\n\n\n\n<p># In[34]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: { &#8220;$regex&#8221;: &#8220;^S&#8221; } }<br \/>mydoc = mycol.find(myquery)<br \/>for x in mydoc:&nbsp; print(x)<\/p>\n\n\n\n<p># In[35]:<\/p>\n\n\n\n<p># Sort<\/p>\n\n\n\n<p># In[36]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mydoc = mycol.find().sort(&#8220;name&#8221;)<br \/>for x in mydoc:&nbsp; print(x)<\/p>\n\n\n\n<p># In[37]:<\/p>\n\n\n\n<p># reverse, alphabetically<\/p>\n\n\n\n<p># In[38]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mydoc = mycol.find().sort(&#8220;name&#8221;, -1)<br \/>for x in mydoc:&nbsp; print(x)<\/p>\n\n\n\n<p># In[39]:<\/p>\n\n\n\n<p>#delete_one, only the first<\/p>\n\n\n\n<p># In[40]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: &#8220;Mountain 21&#8221; }<br \/>mycol.delete_one(myquery)<\/p>\n\n\n\n<p># In[41]:<\/p>\n\n\n\n<p># delete_many<\/p>\n\n\n\n<p># In[42]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: {&#8220;$regex&#8221;: &#8220;^S&#8221;} }<br \/>x = mycol.delete_many(myquery)<br \/>print(x.deleted_count, &#8221; documents deleted.&#8221;)<\/p>\n\n\n\n<p># In[43]:<\/p>\n\n\n\n<p># delete all documents<\/p>\n\n\n\n<p># In[44]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>x = mycol.delete_many({})<br \/>print(x.deleted_count, &#8221; documents deleted.&#8221;)<\/p>\n\n\n\n<p># In[45]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>mycol.drop()<\/p>\n\n\n\n<p># In[46]:<\/p>\n\n\n\n<p># update data: update one<\/p>\n\n\n\n<p># In[47]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: &#8220;Valley 345&#8221; }newvalues = { &#8220;$set&#8221;: { &#8220;address&#8221;: &#8220;Canyon 123&#8221; } }<br \/>mycol.update_one(myquery, newvalues)<br \/>#print &#8220;customers&#8221; after the update:for x in mycol.find():&nbsp; print(x)<\/p>\n\n\n\n<p># In[48]:<\/p>\n\n\n\n<p>#update many<\/p>\n\n\n\n<p># In[49]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myquery = { &#8220;address&#8221;: { &#8220;$regex&#8221;: &#8220;^S&#8221; } }newvalues = { &#8220;$set&#8221;: { &#8220;name&#8221;: &#8220;Minnie&#8221; } }<br \/>x = mycol.update_many(myquery, newvalues)<br \/>print(x.modified_count, &#8220;documents updated.&#8221;)<\/p>\n\n\n\n<p># In[50]:<\/p>\n\n\n\n<p># limit<\/p>\n\n\n\n<p># In[85]:<\/p>\n\n\n\n<p>import pymongo<br \/>myclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;]<br \/>myresult = mycol.find().limit(5)<br \/>#print the result:for x in myresult:&nbsp; print(x)<\/p>\n\n\n\n<p># In[ ]:<\/p>\n\n\n\n<p>Ref: W3Schools<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env python# coding: utf-8# In[63]: import pymongo; # In[64]: import pymongomyclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;] # In[65]: # Check if database exist # In[66]: print(myclient.list_database_names()) # In[67]: dblist = myclient.list_database_names()if &#8220;mydatabase&#8221; in dblist:&nbsp; print(&#8220;The database exists.&#8221;) # In[68]: # Create a collection # In[69]: import pymongomyclient = pymongo.MongoClient(&#8220;mongodb:\/\/localhost:27017\/&#8221;)mydb = myclient[&#8220;mydatabase&#8221;]mycol = mydb[&#8220;customers&#8221;] # In[70]: #collection &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=74659\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1428],"tags":[],"class_list":["post-74659","post","type-post","status-publish","format-standard","hentry","category-python","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":74657,"url":"http:\/\/bangla.sitestree.com\/?p=74657","url_meta":{"origin":74659,"position":0},"title":"Python and MySQL Operations. Code Examples","author":"Sayed","date":"May 17, 2022","format":false,"excerpt":"#!\/usr\/bin\/env python# coding: utf-8# In[1]: import mysql.connector # In[2]: # create a database connection # In[3]: import mysql.connectormydb = mysql.connector.connect(\u00a0 host=\"localhost\",\u00a0 user=\"root\",\u00a0 password=\"\")print(mydb) # In[4]: import mysql.connectormydb = mysql.connector.connect(\u00a0 host=\"localhost\",\u00a0 user=\"root\",\u00a0 password=\"\")mycursor = mydb.cursor()mycursor.execute(\"drop DATABASE mydatabase\");mycursor.execute(\"CREATE DATABASE mydatabase\"); # In[5]: # check if database exists # In[6]: import mysql.connectormydb =\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/bangla.sitestree.com\/?cat=1428"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":74692,"url":"http:\/\/bangla.sitestree.com\/?p=74692","url_meta":{"origin":74659,"position":1},"title":"Misc. Python, MongoDB, MySQL, LMS\/Moodle stuff.","author":"Sayed","date":"May 20, 2022","format":false,"excerpt":"","rel":"","context":"In &quot;Web Development&quot;","block_context":{"text":"Web Development","link":"http:\/\/bangla.sitestree.com\/?cat=6"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7003,"url":"http:\/\/bangla.sitestree.com\/?p=7003","url_meta":{"origin":74659,"position":2},"title":"MongoDB Java","author":"Author-Check- Article-or-Video","date":"March 16, 2015","format":false,"excerpt":"Done By Raju(DU) MongoDB Java Installation \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf\u0983 Java program \u098f MongoDB \u09ac\u09cd\u09af\u09be\u09ac\u09b9\u09be\u09b0 \u0995\u09b0\u09be\u09b0 \u09aa\u09c2\u09b0\u09cd\u09ac\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0\u0995\u09c7 \u09a8\u09bf\u09b6\u09cd\u099a\u09bf\u09a4 \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7 \u09af\u09c7 MongoDB JDBC Driver \u098f\u09ac\u0982 Java \u0986\u09ae\u09be\u09a6\u09c7\u09b0 machine \u098f \u09aa\u09c2\u09b0\u09cd\u09ac\u09c7 \u09a5\u09c7\u0995\u09c7\u0987 \u09b0\u09df\u09c7\u099b\u09c7\u0964 \u0986\u09aa\u09a8\u09bf \u0986\u09b0\u0993 Java tutorial \u09a6\u09c7\u0996\u09a4\u09c7 \u09aa\u09be\u09b0\u09c7\u09a8 \u0986\u09aa\u09a8\u09be\u09b0 machine \u098f Java installation \u0995\u09b0\u09be\u09b0 \u099c\u09a8\u09cd\u09af\u0964 \u098f\u0996\u09a8 \u09a6\u09c7\u0996\u09ac\u09c7 \u0995\u09bf\u09ad\u09be\u09ac\u09c7 MongoDB JDBC driver \u099f\u09bf\u2026","rel":"","context":"In &quot;\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB&quot;","block_context":{"text":"\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB","link":"http:\/\/bangla.sitestree.com\/?cat=222"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26390,"url":"http:\/\/bangla.sitestree.com\/?p=26390","url_meta":{"origin":74659,"position":3},"title":"Basic Data Handling Functions in Python using pandas library #Python #Python #Introduction to Python","author":"Author-Check- Article-or-Video","date":"April 23, 2021","format":false,"excerpt":"\u00a0 # import pandas library import pandas as pd # read the online file by the URL provides above, and assign it to variable \"df\" path=\"https:\/\/......\" df = pd.read_csv(path,header=None) print(\"Done\") # show the first 5 rows using dataframe.head() method df.head(5) # create headers list headers = [\"name\", \"price\", \"make\"] #show\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16964,"url":"http:\/\/bangla.sitestree.com\/?p=16964","url_meta":{"origin":74659,"position":4},"title":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time","author":"Sayed","date":"March 21, 2020","format":false,"excerpt":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time By Sayed Ahmed Merge multiple transaction files into one. This is an extension to the article: Python: Read RBC Canada: Mastercard PDF Statement Transaction Data into CSV file By Sayed Ahmedmedium.com The Code for Merging\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17283,"url":"http:\/\/bangla.sitestree.com\/?p=17283","url_meta":{"origin":74659,"position":5},"title":"WordPress to Medium using Python Code","author":"Sayed","date":"July 5, 2020","format":false,"excerpt":"From: https:\/\/medium.com\/@krisshaffer\/a-journey-through-api-programming-part-4-posting-to-medium-ad6e1b243429 \"from medium import Client import requests client = Client(application_id=\"xxxxxxxxxxx\", application_secret=\"xxxxxxxxxxxxxxxxxxxxxxxxx\") auth_url = client.get_authorization_url(\u201csecretstate\u201d, \u201chttps:\/\/pushpullfork.com\/callback\", [\u201cbasicProfile\u201d, \u201cpublishPost\u201d])print(auth_url)\" \"auth = client.exchange_authorization_code(\u201cXXXXXXXX\u201d, \u201chttps:\/\/pushpullfork.com\/callback\")client.access_token = auth[\u201caccess_token\u201d]user = client.get_current_user()\" \"post = client.create_post(user_id=user[\"id\"], title=\"Title\", content=\"<h2>Test title<\/h2><p>Trying to post with the Medium API.<\/p>\", content_format=\"html\", publish_status=\"draft\")\" *** . *** *** . *** . *** . ***\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/74659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74659"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/74659\/revisions"}],"predecessor-version":[{"id":74660,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/74659\/revisions\/74660"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74659"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}