[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-572434-105":53,"doc-detail-572434-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","","Concise pandas cheat sheet focused on data wrangling workflows with DataFrames, including creating tables via DataFrame constructors, and improving readability through method chaining. Covers tidy data principles, reshaping techniques like melt, pivot, and concatenation, plus row and column subsetting using boolean filters, sampling, loc/iloc, regex-based selection, and index operations. Includes core logic operators, sorting, renaming, duplicates handling, missing-data strategies, summarization, join patterns, and basic feature engineering for new columns.",{"@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/572434/",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/572434.png","ImageObject",442,249,{"name":88,"@type":89},"pop out","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",6,{"@type":103,"mainEntity":104},"FAQPage",[105,111,115],{"name":106,"@type":107,"acceptedAnswer":108},"How do you create a pandas DataFrame in different ways?","Question",{"text":109,"@type":110},"Use pd.DataFrame with a dict to define columns and an index, or pass a list of rows with index and columns. For MultiIndex examples, construct a MultiIndex and provide it as the DataFrame index.","Answer",{"name":112,"@type":107,"acceptedAnswer":113},"What is method chaining in pandas, and why use it?",{"text":114,"@type":110},"Method chaining applies multiple pandas operations in sequence, passing the result of one call into the next. It improves code readability by keeping transformations in one expression.",{"name":116,"@type":107,"acceptedAnswer":117},"Which pandas methods help reshape data between wide and long formats?",{"text":118,"@type":110},"Use pd.melt to gather columns into rows, pivot/df.pivot to spread rows into columns, and pd.concat to append rows or columns depending on the axis parameter.","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},572434,1792255747,{"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":73,"language":136,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":61,"update_tm":140,"read_time":9},962090760408,"https://ap-avatar.wpscdn.com/davatar_085a072bc5b1113ac321206ff7593b45","Data Wrangling  \nwith pandas  \nCheat Sheet [http://pandas.pydata.org](http://pandas.pydata.org)  \n\n|  |  |  |\n| --- | --- | --- |\n| | Syntax – Creating DataFrames | |\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 ([[4, 7, 10],[5, 8, 11],[6 , 9, 12]], 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/ T","cbCaiqDfEQFipkNK","https://ap.wps.com/l/cbCaiqDfEQFipkNK","pdf",243283,"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# Logic in Python (and pandas)\n# Subset Variables (Columns)\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 pandas DataFrame in different ways?\",\"answer\":\"Use pd.DataFrame with a dict to define columns and an index, or pass a list of rows with index and columns. For MultiIndex examples, construct a MultiIndex and provide it as the DataFrame index.\"},{\"question\":\"What is method chaining in pandas, and why use it?\",\"answer\":\"Method chaining applies multiple pandas operations in sequence, passing the result of one call into the next. It improves code readability by keeping transformations in one expression.\"},{\"question\":\"Which pandas methods help reshape data between wide and long formats?\",\"answer\":\"Use pd.melt to gather columns into rows, pivot/df.pivot to spread rows into columns, and pd.concat to append rows or columns depending on the axis parameter.\"}]","Data Wrangling with pandas - Cheat Sheet | PDF",1791927395]