[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-572438-105":3,"detail-sidebar-cat-1-en-105":81,"doc-detail-572438-en":127},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","cheat-sheet-pandas-dataframe-object-quick-reference","Cheat Sheet - pandas DataFrame Object - Quick Reference","","A practical cheat sheet for the pandas DataFrame object, covering essential setup and core mental models. It explains how DataFrames relate to Series, including indexes for columns (df.columns) and rows (df.index), and how Series arithmetic aligns by index for vectorized operations. The guide then walks through creating DataFrames, loading data from CSV strings, Excel workbooks, and SQL tables, and combining Series into DataFrames, followed by basic saving and inspection workflows.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/presentations/","Presentations",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/cheat-sheet-pandas-dataframe-object-quick-reference/572438/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/cheat-sheet-pandas-dataframe-object-quick-reference/572438.png","ImageObject",442,249,{"name":42,"@type":43},"Rainbow Cat","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-21","2026-10-13",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",6,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"What are the main DataFrame components and how do indexes work?","Question",{"text":63,"@type":64},"A DataFrame is a two-dimensional table with column and row indexes. Typically df.columns is a list of strings, while df.index may be integers, strings, or time-series indexes like DatetimeIndex/PeriodIndex.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How does Series arithmetic relate to DataFrame operations?",{"text":68,"@type":64},"Series arithmetic is vectorized, but operands are first aligned by their Series index. After alignment, operations produce results with index-aware behavior.",{"name":70,"@type":61,"acceptedAnswer":71},"What are common ways to load data into a DataFrame?",{"text":72,"@type":64},"The sheet shows loading from CSV files with pd.read_csv, from inline CSV text using StringIO with pd.read_csv, from Excel workbooks via pd.ExcelFile + parse, and from MySQL tables using pd.read_sql_table with a SQLAlchemy engine.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},572438,1792286249,{"code":4,"msg":82,"data":83},"success",[84,88,93,98,103,108,113,118,123],{"id":85,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":86,"slug":87},11,90,"presentations",{"id":89,"doc_module":22,"doc_module_name":25,"category_name":90,"show_sort_weight":91,"slug":92},12,"Resumes",80,"resumes",{"id":94,"doc_module":22,"doc_module_name":25,"category_name":95,"show_sort_weight":96,"slug":97},14,"Invoices",70,"invoices",{"id":99,"doc_module":22,"doc_module_name":25,"category_name":100,"show_sort_weight":101,"slug":102},15,"Posters",60,"posters",{"id":104,"doc_module":22,"doc_module_name":25,"category_name":105,"show_sort_weight":106,"slug":107},16,"Social Media",50,"social-media",{"id":109,"doc_module":22,"doc_module_name":25,"category_name":110,"show_sort_weight":111,"slug":112},17,"Forms",40,"forms",{"id":114,"doc_module":22,"doc_module_name":25,"category_name":115,"show_sort_weight":116,"slug":117},18,"Letters",30,"letters",{"id":119,"doc_module":22,"doc_module_name":25,"category_name":120,"show_sort_weight":121,"slug":122},21,"Paper Templates",5,"papers-templates",{"id":124,"doc_module":22,"doc_module_name":25,"category_name":125,"show_sort_weight":4,"slug":126},158,"General","general-158",{"code":4,"msg":82,"data":128},{"doc_id":79,"user_id":129,"nickname":42,"user_avatar":130,"doc_module":22,"category_id":85,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":131,"file_id":132,"file_url":133,"file_type":134,"file_size":135,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":89,"language":136,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":12,"update_tm":140,"read_time":33},962090769181,"https://ap-avatar.wpscdn.com/davatar_6f874abed73319feea01a86fa6f0fab8","Cheat Sheet: The pandas DataFrame Object  \nPreliminaries  \nAlways start by importing these Python modules  \nimport numpy as np  \nimport matplotlib.pyplot as plt  \nimport pandas as pd  \nfrom pandas import DataFrame, Series  \nNote: these are the recommended import aliases  \nNote: you can put these into a PYTHONSTARTUP file  \nCheat sheet conventions  \nCode examples  \n\\# Code examples are found in yellow boxes  \nIn the code examples, typically I use:  \n􀁸 s to represent a pandas Series object;  \n􀁸 df to represent a pandas DataFrame object;  \n􀁸 idx to represent a pandas Index object.  \n􀁸 Also: t – tuple, l – list, b – Boolean, i – integer, a – numpy array, st – string, d – dictionary, etc.  \nThe conceptual model  \nDataFrame object: is a two-dimensional table of data with column and row indexes (something like a spreadsheet) . The columns are made up of Series objects.  \nColumn index (df.columns)  \nA DataFrame has two Indexes:  \n􀁸 Typically, the column index (df.columns) is a list of strings (variable names) or (less commonly) integers  \n􀁸 Typically, the row index (df. index) might be:  \no Integers-for case or row numbers;  \no Strings – for case names; or  \no DatetimeIndex or PeriodIndex – for time series  \nSeries object: an ordered, one-dimensional array of data with an index. All the data in a Series is of the same data type. Series arithmetic is vectorised after first aligning the Series index for each of the operands.  \n\n| s1\u003Cbr>s2 | =\u003Cbr>= | Series(range(0,4))\u003Cbr>Series(range(1,5)) | \\#\\# | - >\u003Cbr>- > | 0,\u003Cbr>1, | 1,\u003Cbr>2, | 2, 3\u003Cbr>3, 4 |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| s3 | = | s1 + s2 | \\# | - > | 1, | 3, | 5, 7 |\n\nGet your data into a DataFrame  \nInstantiate an empty DataFrame  \ndf = DataFrame()  \nLoad a DataFrame from a CSV file  \n[df = pd.read_csv](df = pd.read_csv) ('file.csv') \\# often works  \n[df = pd.read_csv](df = pd.read_csv) ('file.csv', header=0, index_col=0, quotechar='\"', sep=':', na_values = ['na', ' - ', ' . ', ''])  \nNote: refer to pandas docs for all arguments Get data from inline CSV text to a DataFrame  \nfrom io import StringIO  \ndata = \"\"\", Animal, Cuteness, Desirable  \nrow-1,  \nrow-2,  \nrow-3,  \ndog,  \ncat,  \nbat,  \n8.7, True  \n9.5, True  \n2.6, False\"\"\"  \n[df = pd.read_csv](df = pd.read_csv) (StringIO(data), header=0, index_col=0, skipinitialspace=True)  \nNote: skipinitialspace=True allows for a pretty layout Load DataFrames from a Microsoft Excel file  \n\\# Each Excel sheet in a Python dictionary workbook = pd. ExcelFile('file.xlsx') d = {} \\# start with an empty dictionary for sheet_name in workbook.sheet_names:  \ndf = workbook.parse(sheet_name) d[sheet_name] = df  \nNote: the parse() method takes many arguments like read_csv() above. Refer to the pandas documentation.  \nLoad a DataFrame from a MySQL database  \nimport pymysql  \nfrom sqlalchemy import create_engine  \nengine = create_engine('mysql+pymysql://'+'USER:PASSWORD@HOST/DATABASE') [df = pd.read_sql_table](df = pd.read_sql_table) ('table', engine)  \nData in Series then combine into a DataFrame  \n\\# Example 1 ...  \ns1 = Series(range(6)) s2 = s1 * s1  \ns2 .index = s2 .index + 2 \\# misalign indexes df = pd.concat([s1, s2], axis=1)  \n\\# Example 2 ...  \ns3 = Series({'Tom':1, 'Dick':4, 'Har':9})  \ns4 = Series({'Tom':3, 'Dick':2, 'Mar':5}) df = pd.concat({'A':s3, 'B':s4 }, axis=1)  \nNote: 1st method has in integer column labels Note: 2nd method does not guarantee col order  \nGet a DataFrame from a Python dictionary  \n\\# default --- assume data is in columns df = DataFrame({  \n'col0' : [1.0, 2.0, 3.0, 4.0],  \n'col1' : [100, 200, 300, 400]})  \nVersion 30 April 2017- [Draft – Mark Graph – mark dot the dot graph at gmail dot com – @Mark_Graph on twitter] 1  \nGet a DataFrame from data in a Python dictionary  \n\\# --- use helper method for data in rows df = DataFrame.from_dict({ \\# data by row  \n\\# rows as python dictionaries'row0' : {'col0':0, 'col1':'A'},'row1' : {'col0':1, 'col1':'B'}  \n}, orient='index')  \ndf = DataFrame.from_dict({ \\# dat","cbCaieilyEE34FKS","https://ap.wps.com/l/cbCaieilyEE34FKS","pdf",888732,"English","# Preliminaries\n## Import conventions\n# Conceptual model\n## DataFrame and Series\n# Working with DataFrames\n## Create and load data\n## Save and inspect","[{\"question\":\"What are the main DataFrame components and how do indexes work?\",\"answer\":\"A DataFrame is a two-dimensional table with column and row indexes. Typically df.columns is a list of strings, while df.index may be integers, strings, or time-series indexes like DatetimeIndex/PeriodIndex.\"},{\"question\":\"How does Series arithmetic relate to DataFrame operations?\",\"answer\":\"Series arithmetic is vectorized, but operands are first aligned by their Series index. After alignment, operations produce results with index-aware behavior.\"},{\"question\":\"What are common ways to load data into a DataFrame?\",\"answer\":\"The sheet shows loading from CSV files with pd.read_csv, from inline CSV text using StringIO with pd.read_csv, from Excel workbooks via pd.ExcelFile + parse, and from MySQL tables using pd.read_sql_table with a SQLAlchemy engine.\"}]","Cheat Sheet - pandas DataFrame Object - Quick Reference | PDF",1791927401]