{"id":3346,"date":"2020-06-23T22:34:27","date_gmt":"2020-06-23T20:34:27","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3346"},"modified":"2020-06-23T22:34:27","modified_gmt":"2020-06-23T20:34:27","slug":"python-a-quick-selection","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3346","title":{"rendered":"Python &#8211; a quick selection"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I wrote a Python programme to select rows that contain NULLs. Whenever a  null was found, it is written to a separate file. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The programme uses data frames. This allows to treat data as matrix. Once it is interpreted as a matrix, one may inspect each row. If the row contains a NULL, it is written to an external file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import pandas as pd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ff = pd.read_csv(&#8216;C:\\Users\\tmaanen\\CloudStation\\Pensioenfonds\\moeilijk\\ff.csv&#8217;, delimiter=&#8217;;&#8217;,header=0)<br>dfObjNULL = pd.DataFrame()<br>dfObjnonNULL = pd.DataFrame()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">for i in range(ff.shape[0]):<br>if ff.iloc[i,:].isnull().sum() &gt; 0:<br>dfObjNULL = dfObjNULL.append(ff.iloc[i,:])<br>else:<br>dfObjnonNULL = dfObjnonNULL.append(ff.iloc[i,:])<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dfObjNULL.to_csv (r&#8217;C:\\Users\\tmaanen\\CloudStation\\Pensioenfonds\\moeilijk\\ffNULL.csv&#8217;, index = False, header=True, sep=&#8217;;&#8217;)<br>dfObjnonNULL.to_csv (r&#8217;C:\\Users\\tmaanen\\CloudStation\\Pensioenfonds\\moeilijk\\ffnonNULL.csv&#8217;, index = False, header=True, sep=&#8217;;&#8217;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The idea is rather straightforward. First a file is written. The content is stored in a data frame. The data frame is then inspected row by row. If a NULL is detected the row is appended to a data frame that is set up to store the rows with NULLs. At the end, the data frame is written to a CSV file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote a Python programme to select rows that contain NULLs. Whenever a null was found, it is written to a separate file. The programme uses data frames. This allows to treat data as matrix. Once it is interpreted as a matrix, one may inspect each row. If the row contains a NULL, it is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3346","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3346"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3346\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3346"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}