\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Reszi} \pdfinfo{ /Title (pandas-and-openpyxl.pdf) /Creator (Cheatography) /Author (Reszi) /Subject (pandas and openpyxl Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0808A3} \definecolor{LightBackground}{HTML}{F7F7FC} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{pandas and openpyxl Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Reszi} via \textcolor{DarkBackground}{\uline{cheatography.com/199671/cs/42205/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Reszi \\ \uline{cheatography.com/reszi} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 28th January, 2024.\\ Updated 29th January, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Read/Write and Inspection}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{width=50\}\} \{\{ac\}\} {\bf{Read/Write}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-python\}\}df = \seqsplit{pd.read\_excel('file.xlsx')`} & Read file ({\emph{CSV, Excel, JSON, HTML, SQL}}) \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.to\_csv('file.csv')` & Write file \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Inspection}}} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.head()/.tail()` & View first/last rows \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} `\{\{lang-python\}\}df.shape` & Gives dimensions \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.dtypes` & Shows types in each column ({\emph{int, str etc}}) \tn % Row Count 14 (+ 3) % Row 7 \SetRowColor{white} `\{\{lang-python\}\}df.info` & Lists: ({\emph{range of index, list of all columns, no. non null, data types, memory usage}}) \tn % Row Count 19 (+ 5) % Row 8 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.describe` & Lists: ({\emph{count, mean, std deviation, min, 25\%, 50\%, 75\%, max}}) \tn % Row Count 23 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Filter}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Functionality}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-python\}\}df{[}df{[}'column{]}` vs `\{\{lang-python\}\}df{[}'column'{]}` & 1st filters dataframe, 2nd creates list of booleans \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}df{[}x{]} \textgreater{} y \& df{[}df{[}a{]} \textgreater{} v` & \& combines filters \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} `\{\{lang-python\}\}df{[}df.apply(lamba row: row{[}'col1'{]} * 2 \textgreater{} row{[}'col2'{]}, axis=0)` & Filter by function. Axis=0 for columns, 1 for rows. \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.reset\_index(drop=True)` & Reset indexs for filter \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Rows and Columns}}} \tn % Row Count 16 (+ 1) % Row 6 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}{[}'column1', 'column2'{]}{]}` & Filter by columns \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} `\{\{lang-python\}\}df.iloc{[}1:5{]}` & Filter by row (2nd - 6th) \tn % Row Count 21 (+ 2) % Row 8 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}df{[}'column'{]} \textgreater{} value` & Filters rows based on boolean \tn % Row Count 23 (+ 2) % Row 9 \SetRowColor{white} `\{\{lang-python\}\}df{[}df{[}'column'{]}.isin({[}value1, value2{]})` & Filter rows based on list of values \tn % Row Count 26 (+ 3) % Row 10 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.query('age \textgreater{} @min\_age')` & Filter rows based on query string, @ points to variable 'and' to combine \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Filter (cont)}} \tn % Row 11 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.loc{[}df{[}'column'{]} \textgreater{} value, 'column\_name'{]}` & Filters rows and columns \tn % Row Count 3 (+ 3) % Row 12 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Dropping and replacing}}} \tn % Row Count 4 (+ 1) % Row 13 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.drop(columns={[}'column1', 'column2'{]})' or \{\{nl\}\} '\{\{lang-python\}\}df.drop({[}'unnecessary\_column'{]}, axis=1, inplace=True)` & Drop columns \tn % Row Count 11 (+ 7) % Row 14 \SetRowColor{white} `\{\{lang-python\}\}df.drop\_duplicates(subset={[}'column'{]})` & Drop duplicate rows from specific columns \tn % Row Count 14 (+ 3) % Row 15 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.dropna()` vs `\{\{lang-python\}\}.notna()` & Removes rows with missing values/non-missing values \tn % Row Count 17 (+ 3) % Row 16 \SetRowColor{white} `\{\{lang-python\}\}df.mask/.where(df{[}'column'{]} \textgreater{} value)` & Replaces rows not meeting/meeting condition with NaN \tn % Row Count 20 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{String}}} \tn % Row Count 21 (+ 1) % Row 18 \SetRowColor{white} `\{\{lang-python\}\}df{[}df{[}'column'{]}.str.contains('substring')` & Fitler where string column contains substring \tn % Row Count 24 (+ 3) % Row 19 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}df{[}'column'{]}.str.match(r'abc\$'){]}` & `\{\{lang-python\}\}\textasciicircum{}abc`: Start with 'abc'; `\{\{lang-python\}\}abc\$`: End with 'abc'; `\{\{lang-python\}\}a|b:` 'a' or 'b'; `\{\{lang-python\}\}abc+`: 'abc' followed by 1+ 'c's; `\{\{lang-python\}\}abc*`: 'ab' followed by 0+ 'c's; `\{\{lang-python\}\}abc?`: 'ab' followed by 0 or 1 'c'; `\{\{lang-python\}\}{[}abc{]}`: Any one of 'a', 'b', or 'c' \tn % Row Count 40 (+ 16) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Data Manipulation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Editing data}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-python\}\}df{[}'new\_column'{]} = new\_values` & Assign/create new values for column \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}'column'{]} *= value` & Multiply (/=, -= , +=) each entry in a column by a value. \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} `\{\{lang-python\}\}df.fillna(value or method)` & Fill Nan values \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}'column'{]}.replace(to\_replace, value)` & Replace values \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} `\{\{lang-python\}\}df{[}'column'{]}.rolling(window=7).mean()` & Rolling aggregate \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.update(other\_df)` & Updates values from other df \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} `\{\{lang-python\}\}df{[}'column'{]}.astype(dtype)` & Converts data type \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} `\{\{lang-python\}\}np.where(df{[}'column'{]}\textgreater{} value, 'Value=True', 'Value=False')` & Create array based on new conditions \tn % Row Count 25 (+ 4) % Row 9 \SetRowColor{white} `\{\{lang-python\}\}df{[}'column'{]}.apply(lambda/function name))` & Apply functions to selection \tn % Row Count 28 (+ 3) % Row 10 \SetRowColor{LightBackground} `\{\{lang-python\}\}df.rename(columns=\{'old\_name': 'new\_name'\})` & Rename columns \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Data Manipulation (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Combining data}}} \tn % Row Count 1 (+ 1) % Row 12 \SetRowColor{white} `\{\{lang-python\}\}pd.merge(df1,df2, on='common column', how='inner')`or \{\{nl\}\} `\{\{lang-python\}\}pd.merge(df1, df2, left\_index=True, right\_index=True, how='outer')` & Merges two dfs based on a common column. 'inner' requires both df to have all columns filled vs 'outer, 'left' vs 'right' to filter for columns of either df \tn % Row Count 9 (+ 8) % Row 13 \SetRowColor{LightBackground} `\{\{lang-python\}\}pd.concat({[}df1, df2{]})` & Concatenate (combines all values) \tn % Row Count 11 (+ 2) % Row 14 \SetRowColor{white} `\{\{lang-python\}\}df{[}'column'{]}.map(mapping\_dict)` & Create a dictionary from a list to map keys and values to each other \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Group by}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{17.67cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/reszi_1706484284_Screen-Shot-2020-09-19-at-9.21.01-AM-1024x573-1.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-python\}\}grouped = df.groupby({[}'Store', 'Product'{]}).agg(Total\_Sales=('Sales','sum) Average\_Cost=('Cost', 'mean'), Sales\_Count=('Sales', 'count'))` \newline `\{\{lang-python\}\}filtered\_grouped = grouped{[}grouped{[}'Total\_Sales'{]} \textgreater{} 500{]}` \newline Aggregations: `\{\{lang-python\}\}sum; mean; median; min; max; count; size; std` (standard deviation)`; var` (variance)`; first; last; prod` or `product; nunique`(number of unique values)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Pivot}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{17.67cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/reszi_1706483348_reshaping_pivot.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-python\}\}pivoted\_df = df.pivot(index='Date', columns='Variable', values='Value')` \newline `\{\{lang-python\}\}pivot\_table\_df = \seqsplit{df.pivot\_table(index='Date'}, columns='Variable', values='Value', aggfunc='sum')` \newline \newline values (optional): Columns whose data will be aggregated. \newline index: Columns used as index. \newline columns (optional): Columns to pivot into new DataFrame's columns. \newline aggfunc: Aggregation function for values. \newline pivot\_table: aggregates duplicates} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Melt}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{17.67cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/reszi_1706482946_reshaping_melt.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-python\}\} melted\_df = pd.melt(df, id\_vars={[}'id\_column'{]}, \seqsplit{var\_name='variable\_name'}, \seqsplit{value\_name='value\_name')`} \newline id\_vars (optional): Columns to keep unchanged. Otherwise default melted \newline value\_vars (optional): Columns to melt. \newline var\_name (optional): Melted column name. Default is 'variable'. \newline value\_name (optional): Melted values column name. Default is 'value'. \newline col\_level (optional): Multi-index level} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Stack/unstack}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{17.67cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/reszi_1706482178_reshaping_stack.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`stacked\_df = df.stack(level=-1, dropna=True)` \newline Level: The level(s) of the column labels you want to stack. The default is the last level. \newline Dropna: Whether to drop rows in the resulting DataFrame with missing values. Default is True.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Time Operations}} \tn % Row 0 \SetRowColor{LightBackground} `\{\{lang-python\}\}pd.to\_datetime(df{[}'column'{]})` & Converts a column to datetime format \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `\{\{lang-python\}\}pd.Timestamp.now()` & Returns the current date and time \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `\{\{lang-python\}\}df{[}'datetime\_column'{]}.dt.date/.time` & Extracts the date/time from a datetime column \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} `\{\{lang-python\}\}datetime.datetime.strptime(date\_string, format)` & Useful for strings with words and dates, or including hours/minutes, or multiple dates types in one column (requires try except function) \tn % Row Count 15 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Open pyxl}} \tn % Row 0 \SetRowColor{LightBackground} `\{\{lang-python\}\}openpyxl.load\_workbook(filename){\bf{ \{\{nl\}\} }}workbook.save(filename)` & Read/Write \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} `\{\{lang-python\}\}workbook{[}sheetname{]} or workbook.active` & Sheet selection \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Cell Formats}}} \tn % Row Count 9 (+ 1) % Row 3 \SetRowColor{white} `\{\{lang-python\}\}cell.font = Font(size=12)` & Font \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} `\{\{lang-python\}\}cell.number\_format = '0.00\%'` & Cell formats \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} `\{\{lang-python\}\}Alignment(horizontal="center"); \{\{nl\}\} \seqsplit{Border(left=Side(border\_style="thin"}, color="000000"); \{\{nl\}\} PatternFill("solid", fgColor="DDDDDD")` & More cell options \tn % Row Count 23 (+ 8) % Row 6 \SetRowColor{LightBackground} `\{\{lang-python\}\}Comment('Text', 'Author')` & Cell Comments, can change \seqsplit{comment.width/height} too. \tn % Row Count 26 (+ 3) % Row 7 \SetRowColor{white} `\{\{lang-python\}\}sheet.unmerge/merge\_cells('A1:D1')` & Merge/Unmerge \tn % Row Count 29 (+ 3) % Row 8 \SetRowColor{LightBackground} `\{\{lang-python\}\}cell.hyperlink = \seqsplit{'http://www.example.com'`} & Hyperlinks \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Open pyxl (cont)}} \tn % Row 9 \SetRowColor{LightBackground} `\{\{lang-python\}\}ColorScaleRule(start\_type="min", \seqsplit{start\_color="FFFFFF"}, end\_type="max", \seqsplit{end\_color="FF0000")} \{\{nl\}\} \seqsplit{ws.conditional\_formatting.add("A1:A9"}, rule)` & Conditional Formatting \tn % Row Count 8 (+ 8) % Row 10 \SetRowColor{white} `\{\{lang-python\}\}DataValidation(type="list", formula1='"Item1,Item2,Item3"', showDropDown=True) \{\{nl\}\} \seqsplit{ws.add\_data\_validation(dv)`} & Data validation \tn % Row Count 15 (+ 7) % Row 11 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{ac\}\} {\bf{Charts}}} \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{white} `\{\{lang-python\}\}chart = BarChart(), \{\{nl\}\} chart.style = 13, \{\{nl\}\} \seqsplit{sheet.add\_chart(chart)`} & Create, style, then add chart to sheet \tn % Row Count 21 (+ 5) % Row 13 \SetRowColor{LightBackground} `\{\{lang-python\}\}Image('path/to/image'), \seqsplit{sheet.add\_image(img}, 'A1')` & Add images, better for mathplot or other libraries \tn % Row Count 25 (+ 4) % Row 14 \SetRowColor{white} `\{\{lang-python\}\}cell.value = '=SUM(A1:A10)'` & Write formulas \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}