

{"id":145201,"date":"2025-06-02T12:29:15","date_gmt":"2025-06-02T06:59:15","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=145201"},"modified":"2025-06-02T12:47:10","modified_gmt":"2025-06-02T07:17:10","slug":"pandas-dataframe-where-method","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/","title":{"rendered":"Pandas DataFrame where() Method"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:59,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/12r5-dVKkyHckZZP5o_lEAZNCsHYiiLPD\\\/view?usp=sharing&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251205133920\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/12r5-dVKkyHckZZP5o_lEAZNCsHYiiLPD\\\/view?usp=sharing&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-01-22 16:25:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 22:28:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 10:07:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:60,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1xgx68I456XvZMvRzC7QgNmG5x0dqUreF\\\/view?usp=sharing&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251205134026\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1xgx68I456XvZMvRzC7QgNmG5x0dqUreF\\\/view?usp=sharing&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-01-22 16:25:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 22:28:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 10:07:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:61,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1NHVL-U-KMHwpu0lJdZtxsMwjWvKHrFJU\\\/view?usp=sharing&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251205135605\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1NHVL-U-KMHwpu0lJdZtxsMwjWvKHrFJU\\\/view?usp=sharing&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-01-22 16:25:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 22:28:07&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 10:07:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-05-29 05:41:30&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<h3>Program 1<\/h3>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/12r5-dVKkyHckZZP5o_lEAZNCsHYiiLPD\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\"><strong>Pandas Dataset 1<\/strong><\/a><\/p>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1xgx68I456XvZMvRzC7QgNmG5x0dqUreF\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\"><strong>Pandas Dataset 2<\/strong><\/a><\/p>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1NHVL-U-KMHwpu0lJdZtxsMwjWvKHrFJU\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\"><strong>Pandas Dataset 3<\/strong><\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import pandas  as pd\r\ndf=pd.read_excel(\"D:\/\/mypandas\/studentinfo.xlsx\")\r\nprint(df)\r\ndf.set_index('Name',inplace=True)\r\nprint(df)\r\nprint(\"------------------------------------------\")\r\ndf1=df.where(lambda x:x&lt;80,'A+')\r\nprint(df1)\r\ndf1.to_excel(\"D:\/\/resultdata\/agrade.xlsx\")\r\nprint(\"------------------------------------------\")\r\ndf2=df.where(lambda x:x&gt;80,'B+')\r\nprint(df2)\r\ndf2.to_excel(\"D:\/\/resultdata\/bgrade.xlsx\")\r\nprint(\"--------Success--------------\")\r\n\r\n\r\n\r\n# print(df)\r\n# print(\"------------------------------------\")\r\n# df=df.where(df['SSC']&lt;80,'First')\r\n# print(df)\r\n# print(df)\r\n# print(\"------------------------------------\")\r\n# df1=df.where(df&lt;80,'First')\r\n# #print(df.where(df&lt;80,'First'))\r\n# print(\"------------------------------------\")\r\n# print(df1)\r\n\r\n# df2=df.where(df&gt;80,'Second')\r\n\r\n# print(\"------------------------------------\")\r\n# print(df2)\r\n\r\n#df.where(condition,repalce value)\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Program 1 Pandas Dataset 1 Pandas Dataset 2 Pandas Dataset 3 import pandas as pd df=pd.read_excel(&#8220;D:\/\/mypandas\/studentinfo.xlsx&#8221;) print(df) df.set_index(&#8216;Name&#8217;,inplace=True) print(df) print(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;) df1=df.where(lambda x:x&lt;80,&#8217;A+&#8217;) print(df1) df1.to_excel(&#8220;D:\/\/resultdata\/agrade.xlsx&#8221;) print(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;) df2=df.where(lambda x:x&gt;80,&#8217;B+&#8217;) print(df2) df2.to_excel(&#8220;D:\/\/resultdata\/bgrade.xlsx&#8221;) print(&#8220;&#8212;&#8212;&#8211;Success&#8212;&#8212;&#8212;&#8212;&#8211;&#8220;) # print(df) # print(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;)&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19475],"tags":[34311,9393,30082,30038,34264,34310,9399,34309,30083],"class_list":["post-145201","post","type-post","status-publish","format-standard","hentry","category-pandas","tag-how-to-apply-where-method-in-pandas","tag-pandas","tag-pandas-dataframe-where-method","tag-pandas-practical","tag-pandas-program","tag-pandas-program-on-where-method","tag-pandas-tutorial","tag-pandas-where-method","tag-where-method-in-pandas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pandas DataFrame where() Method - DataFlair<\/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:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas DataFrame where() Method - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Program 1 Pandas Dataset 1 Pandas Dataset 2 Pandas Dataset 3 import pandas as pd df=pd.read_excel(&quot;D:\/\/mypandas\/studentinfo.xlsx&quot;) print(df) df.set_index(&#039;Name&#039;,inplace=True) print(df) print(&quot;------------------------------------------&quot;) df1=df.where(lambda x:x&lt;80,&#039;A+&#039;) print(df1) df1.to_excel(&quot;D:\/\/resultdata\/agrade.xlsx&quot;) print(&quot;------------------------------------------&quot;) df2=df.where(lambda x:x&gt;80,&#039;B+&#039;) print(df2) df2.to_excel(&quot;D:\/\/resultdata\/bgrade.xlsx&quot;) print(&quot;--------Success--------------&quot;) # print(df) # print(&quot;------------------------------------&quot;)&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-02T06:59:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-02T07:17:10+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pandas DataFrame where() Method - DataFlair","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:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/","og_locale":"en_US","og_type":"article","og_title":"Pandas DataFrame where() Method - DataFlair","og_description":"Program 1 Pandas Dataset 1 Pandas Dataset 2 Pandas Dataset 3 import pandas as pd df=pd.read_excel(\"D:\/\/mypandas\/studentinfo.xlsx\") print(df) df.set_index('Name',inplace=True) print(df) print(\"------------------------------------------\") df1=df.where(lambda x:x&lt;80,'A+') print(df1) df1.to_excel(\"D:\/\/resultdata\/agrade.xlsx\") print(\"------------------------------------------\") df2=df.where(lambda x:x&gt;80,'B+') print(df2) df2.to_excel(\"D:\/\/resultdata\/bgrade.xlsx\") print(\"--------Success--------------\") # print(df) # print(\"------------------------------------\")&#46;&#46;&#46;","og_url":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2025-06-02T06:59:15+00:00","article_modified_time":"2025-06-02T07:17:10+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Pandas DataFrame where() Method","datePublished":"2025-06-02T06:59:15+00:00","dateModified":"2025-06-02T07:17:10+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/"},"wordCount":12,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["how to apply where method in pandas","Pandas","pandas dataframe where method","pandas practical","pandas program","pandas program on where() method","pandas tutorial","pandas where() method","where method in pandas"],"articleSection":["Pandas Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/","url":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/","name":"Pandas DataFrame where() Method - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2025-06-02T06:59:15+00:00","dateModified":"2025-06-02T07:17:10+00:00","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/pandas-dataframe-where-method\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Pandas Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/pandas\/"},{"@type":"ListItem","position":3,"name":"Pandas DataFrame where() Method"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=145201"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145201\/revisions"}],"predecessor-version":[{"id":145216,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145201\/revisions\/145216"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=145201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=145201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=145201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}