{"id":923,"date":"2021-12-12T19:57:13","date_gmt":"2021-12-13T01:57:13","guid":{"rendered":"https:\/\/asberry.org\/blog_tech\/?p=923"},"modified":"2021-12-12T19:57:13","modified_gmt":"2021-12-13T01:57:13","slug":"python-merge-csvs","status":"publish","type":"post","link":"https:\/\/asberry.org\/blog_tech\/?p=923","title":{"rendered":"Python &#8211; Merge CSV&#8217;s"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;m really enjoying python, one of the things that I&#8217;m really digging is pandas, this piece lets you work with CSV files to do a multitude of things. Because you have to pull out data in a loop, this little piece of code will allow you to stitch them together. This sample uses pipe delimiters with UNIX line feeds and quoted all. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\nimport os\nimport glob\nimport pandas as pd\nimport csv\n#os.chdir(&quot;C:\\\\onedrive_tt\\\\Testing\\python\\\\CombineCSVs\\\\testApplicationFiles&quot;)\nos.chdir(&quot;C:\\\\app\\\\python\\\\CombineCSVs\\\\testApplicationFiles&quot;)\n\nextension = &#039;csv&#039;\nall_filenames = &#x5B;i for i in glob.glob(&#039;*.{}&#039;.format(extension))]\n\n#combine all files in the list\ncombined_csv = pd.concat(&#x5B;pd.read_csv(f, sep = &#039;|&#039;, dtype=str) for f in all_filenames ])\n#export to csv\ncombined_csv.to_csv( &quot;combined_csv.csv&quot;, sep=&#039;|&#039;, index=False, encoding=&#039;utf-8&#039;, line_terminator=&quot;\\n&quot;, quoting=csv.QUOTE_ALL)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m really enjoying python, one of the things that I&#8217;m really digging is pandas, this piece lets you work with CSV files to do a multitude of things. Because you have to pull out data in a loop, this little piece of code will allow you to stitch them together. This sample uses pipe delimiters [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[24],"tags":[],"class_list":["post-923","post","type-post","status-publish","format-standard","hentry","category-python","author-aron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4bBkH-eT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=923"}],"version-history":[{"count":1,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":925,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/923\/revisions\/925"}],"wp:attachment":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}