\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{dfadda} \pdfinfo{ /Title (dvva18-pandas.pdf) /Creator (Cheatography) /Author (dfadda) /Subject (dvva18 pandas 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{dvva18 pandas Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{dfadda} via \textcolor{DarkBackground}{\uline{cheatography.com/59692/cs/15632/}}} \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}dfadda \\ \uline{cheatography.com/dfadda} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 1st May, 2018.\\ 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{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Importare pandas e numpy}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`import pandas as pd`\{\{nl\}\} importa la libreria pandas} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`import numpy as np`\{\{nl\}\}importa la libreria numpy} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`pd.set\_option('max\_columns'}, 300)`\{\{nl\}\}limitare il numero di colonne stampate in output:*} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`pd.set\_option('max\_rows'}, 1000)`\{\{nl\}\}limitare il numero di righe stampate in output:*} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Creare una serie}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`my\_data = {[}10,20,30{]}` e `labels = {[}'A','B','C'{]}`\{\{nl\}\} `pd.Series(data=my\_data, index=labels)`} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Caricare un file in un dataframe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`df=pd.read\_csv("file.csv")`} Legge un file csv} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{parametri aggiuntivi:} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`header` specifca la riga da usare come header (int type), nel caso non sia presente: `header=None`} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`sep=';'` specifica il separatore usato nel file csv} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`names={[}'col1','col2'{]}` esplicita il nome delle colonne del dataframe, utile soprattutto in caso non ci sia header nel file} \tn % Row Count 9 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`parse\_dates = {[}'col1','col2'{]}` lista di interi nomi di colonne da tentare di parsare come data.} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`df=pd.read\_excel("nomefile.xlsx")`} legge un file excel} \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Salvare un dataframe in csv}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`df.to\_csv('path/file\_name.csv'},sep=';', index=False) `\{\{nl\}\} salva il dataframe in un file csv (rimuovendo l'indice e usando come sepraratore il ;)} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Esplorare un dataframe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.shape`\{\{nl\}\}restituisce (numero righe, numero colonne)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}df.isnull().any(axis=1){]}`\{\{nl\}\}controlla se ci sono valori nulli} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.dtypes `\{\{nl\}\}restituisce il tipo di variabile di ogni colonna} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.head()`\{\{nl\}\}restituisce le prime (n) righe di un dataframe (default = 5)} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.tail()`\{\{nl\}\}restituisce le ultime (n) righe di un dataframe (default = 5)} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.columns`\{\{nl\}\}restituisce l'elenco delle colonne del dataframe} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.describe()`\{\{nl\}\}restituisce una descrizione del dataframe con le statistiche di base} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gestire i dati mancanti}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.dropna(axis=0)` \{\{nl\}\} Elimina le righe con valori null presenti in qualsiasi colonna} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.dropna(axis=1)` \{\{nl\}\} Elimina le colonne con valori null} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.dropna(axis=0, thresh=5)` \{\{nl\}\} Elimina le righe con almeno 5 valori null presenti in qualsiasi colonna} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.fillna(value='VALORE NUOVO')` \{\{nl\}\} Riempi le righe con valori null usando il valore {\emph{value}} indicato tra parentesi} \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Reshape dei dati}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.sort\_values(by={[}'col1','col2'{]})`\{\{nl\}\}ordina il dataframe per colonna o array di colonne} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`df.sort\_values(by='col1'},ascending = False)`\{\{nl\}\}ordina il dataframe per colonna in ordine discendente} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.sort\_index()` \{\{nl\}\}ordina l'indice del dataframe} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.reset\_index()`\{\{nl\}\}resetta l'indice del dataframe usando l'ordine delle righe, l'indice attuale viene salvato in una nuova colonna} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`df.reset\_index(name='new} name')`\{\{nl\}\}assegna il nome alla colonna indice durante la fase di reset} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.drop(columns={[}'col1','col2'{]})`\{\{nl\}\}elimina le colonne 'col1' e 'col2'} \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.rename(columns=\{'old\_column : 'new column', 'old\_column2 : 'new column2'\})`\{\{nl\}\}rinomina le colonne (usando un dizionario)} \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{bt\}\} `df.concat({[}df1,df2{]})`\{\{nl\}\}aggiunge le righe del df2 al df1} \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.concat({[}df1,df2{]}, axis=1)`\{\{nl\}\}aggiunge le colonne del df2 al df1} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ricavare un sottoinsieme di un dataframe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{per righe}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}df{[}'colonna1'{]}\textgreater{}n{]}`\{\{nl\}\} seleziona tutte le righe dove nella {\emph{colonna1}} i valori sono maggiori di {\emph{n}}} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.drop\_duplicates()`\{\{nl\}\} rimuove le righe duplicate} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.iloc{[}10:20{]}`\{\{nl\}\} seleziona tutte le righe dalla 10 alla 20} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}df{[}'column'{]}.isin({[}'value1','value2'{]}){]}`\{\{nl\}\} seleziona tutte le righe dove il valore nella colonna {\emph{column}} è uguale a {\emph{value1}} o {\emph{value2}}} \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column'{]}.unique()`\{\{nl\}\}restituisce i valori unici di una colonna} \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{per colonne}}} \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'colonna1'{]}` o `df.colonna1`\{\{nl\}\} seleziona la colonna 1} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}{[}'colonna1','colonna2','colonna4'{]}{]}`\{\{nl\}\} Seleziona le colonne 1,2,4} \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.iloc{[}10:20, {[}1,2,5{]}{]}`\{\{nl\}\} seleziona tutte le righe dalla 10 alla 20 e le colonne in posizione 1,2,5} \tn % Row Count 21 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.loc{[}:, 'x2':'x4'{]}`\{\{nl\}\} seleziona tutte le colonne dalla posizione x2 alla posizione x4 (compresa)} \tn % Row Count 24 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df.loc{[}df{[}'a'{]}\textgreater{}10,{[}'a','c'{]}{]}`\{\{nl\}\} seleziona le colonne {\emph{'a'}} e {\emph{'c'}} dove il valore di a è maggiore di 10} \tn % Row Count 27 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Varie}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df.columns` \{\{nl\}\} restituisce l'elenco delle colonne} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`del df{[}'col\_1'{]}` \{\{nl\}\} elimina una colonna} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Riassumere i dati}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`len(df) ` \{\{nl\}\} number of rows in a dataframe} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.nunique()` \{\{nl\}\} numero di valori unici in una colonna} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.sum()` \{\{nl\}\} somma dei valori di una colonna} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.min()` \{\{nl\}\} minimo dei valori di una colonna} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.max()` \{\{nl\}\} massimo dei valori di una colonna} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.mean()` \{\{nl\}\} media dei valori di una colonna} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.var()` \{\{nl\}\} varianza dei valori di una colonna} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.std()` \{\{nl\}\} deviazione standard dei valori di una colonna} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.count()` \{\{nl\}\} count dei valori non nulli di una colonna} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.median()` \{\{nl\}\} mediana dei valori di una colonna} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.quantile({[}.25,.75{]})` \{\{nl\}\} quantile dei valori di una colonna} \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'column1'{]}.value\_count()` \{\{nl\}\} count di ogni valore di una colonna} \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Gestione oggetti di tipo datetime}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}=pd.to\_datetime(df{[}'Data'{]})`\{\{nl\}\} converte stringhe in oggetti datetime} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.round('1s')`\{\{nl\}\} arrotonda la data al secondo} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Duration'{]}=(df{[}'Data2'{]}-df{[}'Data1'{]}).dt.seconds `\{\{nl\}\} Calcola la differenza tra due date restituendo un risultato in seocndi} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.date`\{\{nl\}\} estrae solo la data da data ora} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.month`\{\{nl\}\} estrae il mese} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.week`\{\{nl\}\} estrae la settimana dell'anno} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.weekday`\{\{nl\}\} estrae il giorno della settimana} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.weekday\_name`\{\{nl\}\} estrae il giorno della settimana (come nome)} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.time`\{\{nl\}\} estrae l'ora completa} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Data'{]}.dt.hour`\{\{nl\}\} estrae l'ora} \tn % Row Count 18 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'Stagione'{]}=pd.cut( (df{[}'Data'{]}.dt.dayofyear + 11) \% 366, {[}0, 91, 183, 275, 366{]}, labels={[}'inverno', 'primavera', 'estate', 'autunno'{]} )`\{\{nl\}\} crea una colonna con la corrispondente stagione} \tn % Row Count 23 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Crea ed elimina colonne/righe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df{[}'new\_column'{]} = df{[}'col\_1'{]} + df{[}'col\_2'{]}`\{\{nl\}\}crea una nuova colonna somma di due colonne} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`df = df.drop('col\_1', axis=1)`\{\{nl\}\} elimina la colonna {\emph{col\_1}}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`df = df.drop(0, axis=0)`\{\{nl\}\} elimina la riga con indice {\emph{0}}} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}