{"id":245,"date":"2021-09-02T13:08:53","date_gmt":"2021-09-02T13:08:53","guid":{"rendered":"https:\/\/www.jibsheet.net\/linux\/?p=245"},"modified":"2021-09-02T13:14:35","modified_gmt":"2021-09-02T13:14:35","slug":"pandas-python-how-to-drop-a-row-with-nan","status":"publish","type":"post","link":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/","title":{"rendered":"Pandas\/Python &#8211; how to drop a row with &#8216;NaN&#8217;"},"content":{"rendered":"<p>So, you want to get rid of any row that has &#8216;NaN&#8217; ( null or not a number ) values, because it doesn&#8217;t work with some functions ( or can&#8217;t ignore )<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">obs1.dropna(how = 'all', subset = ['wind_mph'], inplace = True)\r\nobs1 = obs1.reset_index(drop=True)<\/pre>\n<p>Another important point &#8211; is that with Pandas &#8211; you have to convert any value you load to NaN.\u00a0 Or somehow change it to the cannonical &#8216;NaN&#8217;.\u00a0 \u00a0here is a way to convert text to &#8216;NaN&#8217;.\u00a0 \u00a0 This might also clean up any automated conversion for columns &#8211; so if 99.9% of your column data is float, but one value text or something &#8211; it will though an internal exception and keep the column as a object.\u00a0 The data my program generates puts a &#8220;&lt;no_value_provided&gt;&#8221;, the parm to use is na_values ( and it can be a list if your data has more than one notation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def date_utc(x): return dateutil.parser.parse(x[:20], ignoretz=True)\r\nobs1 = pd.read_csv(target_csv, parse_dates=[9], date_parser=date_utc,\r\n                    dtype = { 'wind_mph': 'float64'},\r\n                    na_values = \"&lt;no_value_provided&gt;\")<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, you want to get rid of any row that has &#8216;NaN&#8217; ( null or not a number ) values, because it doesn&#8217;t work with some functions ( or can&#8217;t ignore ) obs1.dropna(how = &#8216;all&#8217;, subset = [&#8216;wind_mph&#8217;], inplace = True) obs1 = obs1.reset_index(drop=True) Another important point &#8211; is that with Pandas &#8211; you have to convert any value you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14,7,1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pandas\/Python - how to drop a row with &#039;NaN&#039; - Jon Allen&#039;s Linux Stuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas\/Python - how to drop a row with &#039;NaN&#039; - Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"og:description\" content=\"So, you want to get rid of any row that has &#8216;NaN&#8217; ( null or not a number ) values, because it doesn&#8217;t work with some functions ( or can&#8217;t ignore ) obs1.dropna(how = &#039;all&#039;, subset = [&#039;wind_mph&#039;], inplace = True) obs1 = obs1.reset_index(drop=True) Another important point &#8211; is that with Pandas &#8211; you have to convert any value you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\" \/>\n<meta property=\"og:site_name\" content=\"Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-02T13:08:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-02T13:14:35+00:00\" \/>\n<meta name=\"author\" content=\"jonallen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jonallen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\"},\"author\":{\"name\":\"jonallen\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"headline\":\"Pandas\/Python &#8211; how to drop a row with &#8216;NaN&#8217;\",\"datePublished\":\"2021-09-02T13:08:53+00:00\",\"dateModified\":\"2021-09-02T13:14:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\"},\"wordCount\":147,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"articleSection\":[\"Pandas\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\",\"name\":\"Pandas\/Python - how to drop a row with 'NaN' - Jon Allen&#039;s Linux Stuff\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\"},\"datePublished\":\"2021-09-02T13:08:53+00:00\",\"dateModified\":\"2021-09-02T13:14:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.jibsheet.net\/linux\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pandas\/Python &#8211; how to drop a row with &#8216;NaN&#8217;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/\",\"name\":\"Jon Allen's Linux Stuff\",\"description\":\"Howto&#039;s, Observations, and stuff\",\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\",\"name\":\"jonallen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"caption\":\"jonallen\"},\"logo\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.jibsheet.net\/linux\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pandas\/Python - how to drop a row with 'NaN' - Jon Allen&#039;s Linux Stuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/","og_locale":"en_US","og_type":"article","og_title":"Pandas\/Python - how to drop a row with 'NaN' - Jon Allen&#039;s Linux Stuff","og_description":"So, you want to get rid of any row that has &#8216;NaN&#8217; ( null or not a number ) values, because it doesn&#8217;t work with some functions ( or can&#8217;t ignore ) obs1.dropna(how = 'all', subset = ['wind_mph'], inplace = True) obs1 = obs1.reset_index(drop=True) Another important point &#8211; is that with Pandas &#8211; you have to convert any value you [&hellip;]","og_url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/","og_site_name":"Jon Allen&#039;s Linux Stuff","article_published_time":"2021-09-02T13:08:53+00:00","article_modified_time":"2021-09-02T13:14:35+00:00","author":"jonallen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jonallen","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#article","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/"},"author":{"name":"jonallen","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"headline":"Pandas\/Python &#8211; how to drop a row with &#8216;NaN&#8217;","datePublished":"2021-09-02T13:08:53+00:00","dateModified":"2021-09-02T13:14:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/"},"wordCount":147,"commentCount":0,"publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"articleSection":["Pandas","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/","url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/","name":"Pandas\/Python - how to drop a row with 'NaN' - Jon Allen&#039;s Linux Stuff","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/#website"},"datePublished":"2021-09-02T13:08:53+00:00","dateModified":"2021-09-02T13:14:35+00:00","breadcrumb":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2021\/09\/02\/pandas-python-how-to-drop-a-row-with-nan\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.jibsheet.net\/linux\/"},{"@type":"ListItem","position":2,"name":"Pandas\/Python &#8211; how to drop a row with &#8216;NaN&#8217;"}]},{"@type":"WebSite","@id":"https:\/\/www.jibsheet.net\/linux\/#website","url":"https:\/\/www.jibsheet.net\/linux\/","name":"Jon Allen's Linux Stuff","description":"Howto&#039;s, Observations, and stuff","publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993","name":"jonallen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","caption":"jonallen"},"logo":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.jibsheet.net\/linux"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/245"}],"collection":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":3,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}