[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-571394-105":53,"doc-detail-571394-en":127},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":120,"head_meta":122,"extra_data":124,"updated_unix":126},105,"en","data-wrangling-with-pandas-cheat-sheet","Data Wrangling with pandas - Cheat Sheet","","Data Wrangling with pandas Cheat Sheet consolidates practical pandas operations for reshaping, subsetting, and transforming tabular data. It covers creating DataFrames, chaining multiple steps for readable pipelines, melting and pivoting layouts, concatenating frames, sorting, renaming, and removing duplicates. It also provides row and column selection methods, logical and boolean filtering, regex-based column filtering, and missing-data handling. The sheet includes summarization, descriptive statistics, binning, join patterns, and utilities for counting values and distinct entries.",{"@graph":63,"@context":119},[64,80,102],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/data-wrangling-with-pandas-cheat-sheet/571394/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/data-wrangling-with-pandas-cheat-sheet/571394.png","ImageObject",442,249,{"name":88,"@type":89},"Noah","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-21","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":101},"InteractionCounter",{"@type":100},"ViewAction",7,{"@type":103,"mainEntity":104},"FAQPage",[105,111,115],{"name":106,"@type":107,"acceptedAnswer":108},"How do you create a DataFrame in pandas as shown in the cheat sheet?","Question",{"text":109,"@type":110},"Use pd.DataFrame with either a dictionary of columns and an index, or with a nested list plus index and columns. For MultiIndex creation, the cheat sheet demonstrates using pd.MultiIndex.from_tuples with names.","Answer",{"name":112,"@type":107,"acceptedAnswer":113},"What does method chaining mean in pandas and how is it used here?",{"text":114,"@type":110},"Many pandas methods return a DataFrame, so outputs can feed into the next method. The cheat sheet shows chaining melt, rename, and query to produce a filtered result in a readable pipeline.",{"name":116,"@type":107,"acceptedAnswer":117},"How can you reshape data (wide to long or long to wide) in this cheat sheet?",{"text":118,"@type":110},"Use pd.melt to gather columns into rows, and df.pivot (or pivot-style operations) to spread rows into columns. It also lists concatenation with axis settings to append rows or columns across DataFrames.","https://schema.org",{"og:url":78,"og:type":121,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":123,"canonical":78},"index,follow",{"doc_id":125,"site_id":56},571394,1792242492,{"code":4,"msg":5,"data":128},{"doc_id":125,"user_id":129,"nickname":88,"user_avatar":130,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":131,"file_id":132,"file_url":133,"file_type":134,"file_size":135,"view_count":101,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":136,"language":137,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":138,"faqs":139,"seo_title":140,"seo_description":61,"update_tm":141,"read_time":73},8796095462418,"https://ap-avatar.wpscdn.com/avatar/80000253c1241d02b47?x-image-process=image/resize,m_fixed,w_180,h_180&k=1778826106357471780","Data Wrangling  \nwith pandas  \nCheat Sheet [http://pandas.pydata.org](http://pandas.pydata.org)  \n\n| \u003Cbr>Syntax – Creating DataFrames\u003Cbr>|\n| --- |\n| a b c 1 4 7 10 2 5 8 11 3 6 9 12\u003Cbr>df = pd.DataFrame (\u003Cbr>{\"a\" : [4 , 5 , 6],\"b\" : [7 , 8, 9],\u003Cbr>\"c\" : [10 , 11, 12]}, index = [1 , 2, 3])\u003Cbr>Specify values for each column.\u003Cbr>df = pd.DataFrame (\u003Cbr>[[4, 7, 10],\u003Cbr>[5, 8, 11],\u003Cbr>[6, 9, 12]],\u003Cbr>index=[1, 2, 3],\u003Cbr>columns=['a', 'b', 'c'])\u003Cbr>Specify values for each row.\u003Cbr>a b c n v d 1 4 7 10 2 5 8 11 e 2 6 9 12\u003Cbr>df = pd.DataFrame (\u003Cbr>{\"a\" : [4 , 5 , 6],\"b\" : [7 , 8, 9],\"c\" : [10 , 11, 12]},\u003Cbr>index = pd.MultiIndex.from_tuples (\u003Cbr>[('d',1),('d',2),('e',2)], names=['n','v'])))\u003Cbr>Create DataFrame with a MultiIndex |\n\n\n| Method Chaining |\n| --- |\n| Most pandas methods return a DataFrame so that another pandas method can be applied to the result. This improves readability of code.\u003Cbr>df = (pd.melt(df)\u003Cbr>.rename(columns={'variable ' : 'var','value ' : 'val'})\u003Cbr>.query('val >= 200')) |\n\nTidy Data – A foundation for wrangling in pandas  \ndInaatatisdeyt: &  \nEach variable is saved in its own column  \nTidy data complements pandas’s vectorized operations. pandas will automatically preserve observations as you manipulate variables. No other format works as intuitively with pandas.  \nEach observation is saved in its own row  \nM * A  \n\n| Reshaping Data – Change the layout of a data set |\n| --- |\n|  |\n| \u003Cbr>pd.melt (df)\u003Cbr>Gather columns into rows. \u003Cbr>df.pivot(columns= 'var', values='val')\u003Cbr>Spread rows into columns. \u003Cbr>pd.concat([df1,df2])\u003Cbr>Append rows of DataFrames \u003Cbr>pd.concat([df1,df2], axis=1)\u003Cbr>Append columns of DataFrames\u003Cbr>df.sort_values('mpg ' )\u003Cbr>Order rows by values of a column (low to high) .\u003Cbr>df.sort_values('mpg',ascending=False)\u003Cbr>Order rows by values of a column (high to low) .\u003Cbr>df.rename(columns = {'y':'year'})\u003Cbr>Rename the columns of a DataFrame\u003Cbr>df.sort_index()\u003Cbr>Sort the index of a DataFrame\u003Cbr>df.reset_index()\u003Cbr>Reset index of DataFrame to row numbers, moving index to columns.\u003Cbr>df.drop(columns=[ ' Length','Height'])\u003Cbr>Drop columns from DataFrame |\n\nSubset Observations (Rows)  \ndf [df.Length > 7]  \nExtract rows that meet logical criteria.  \ndf.drop_duplicates()  \nRemove duplicate rows (only considers columns) .  \ndf.head(n)  \nSelect first n rows.  \ndf.tail(n)  \nSelect last n rows.  \ndf.sample (frac=0.5)  \nRandomly select fraction of rows.  \ndf.sample(n=10)  \nRandomly select n rows.  \ndf.iloc[10:20]  \nSelect rows by position.  \ndf.nlargest(n, 'value')  \nSelect and order top n entries.  \ndf.nsmallest(n, 'value')  \nSelect and order bottom n entries.  \n\n| Logic in Python (and pandas) |  |  |  |\n| --- | --- | --- | --- |\n| \u003C | Less than | != | Not equal to |\n| > | Greater than | df.column.isin (values) | Group membership |\n| == | Equals | pd.isnull (obj) | Is NaN |\n| \u003C= | Less than or equals | pd.notnull (obj) | Is not NaN |\n| >= | Greater than or equals | &, |,~,^,df.any(),df.all() | Logical and, or, not, xor, any, all |\n\nSubset Variables (Columns)  \ndf[['width','length','species']]  \nSelect multiple columns with specific names. df['width'] or df.width  \nSelect single column with specific name. df.filter(regex='regex')  \nSelect columns whose name matches regular expression regex.  \n\n| regex (Regular Expressions) Examples |  |\n| --- | --- |\n| '\\ . ' | Matches strings containing a period ' . ' |\n| 'Length$' | Matches strings ending with word 'Length' |\n| '^Sepal' | Matches strings beginning with the word 'Sepal' |\n| '^x[1-5]$' | Matches strings beginning with 'x' and ending with 1,2,3,4,5 |\n| ''^(?!Species$) .*' | Matches strings except the string 'Species' |\n\ndf.loc[:,'x2':'x4 ' ]  \nSelect all columns between x2 and x4 (inclusive) .  \ndf.iloc[:,[1,2,5]]  \nSelect columns in positions 1, 2 and 5 (first column is 0) .  \ndf.loc [df['a'] > 10, ['a','c']]  \nSelect rows meeting logical condition, and only the specific columns .  \n[http://pandas.pydata.org/](http://pandas.pydata.org/ This)[ This](http://","cbCairHUaFrjxucZ","https://ap.wps.com/l/cbCairHUaFrjxucZ","pdf",1398388,6,"English","# Syntax - Creating DataFrames\n## Method Chaining\n# Tidy Data\n# Reshaping Data - Change the layout of a data set\n## Subset Observations (Rows)\n## Subset Variables (Columns)\n# Logic in Python (and pandas)\n## regex (Regular Expressions) Examples\n# Summarize Data\n## Handling Missing Data\n## Make New Columns\n## Combine Data Sets","[{\"question\":\"How do you create a DataFrame in pandas as shown in the cheat sheet?\",\"answer\":\"Use pd.DataFrame with either a dictionary of columns and an index, or with a nested list plus index and columns. For MultiIndex creation, the cheat sheet demonstrates using pd.MultiIndex.from_tuples with names.\"},{\"question\":\"What does method chaining mean in pandas and how is it used here?\",\"answer\":\"Many pandas methods return a DataFrame, so outputs can feed into the next method. The cheat sheet shows chaining melt, rename, and query to produce a filtered result in a readable pipeline.\"},{\"question\":\"How can you reshape data (wide to long or long to wide) in this cheat sheet?\",\"answer\":\"Use pd.melt to gather columns into rows, and df.pivot (or pivot-style operations) to spread rows into columns. It also lists concatenation with axis settings to append rows or columns across DataFrames.\"}]","Data Wrangling with pandas - Cheat Sheet | PDF",1791914960]