python:pandas

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
python:pandas [2023/07/28 16:48] – [Changer la colonne d'index] Precise possible list of columns phswpython:pandas [2023/10/30 12:26] (Version actuelle) – [Renommer des colonnes] add how to name column phsw
Ligne 22: Ligne 22:
 <code python> <code python>
 print(df.to_markdown())  # il faut installer le paquet tabulate / python3-tabulate print(df.to_markdown())  # il faut installer le paquet tabulate / python3-tabulate
 +</code>
 +ou bien :
 +<code python>
 +pd.set_option("display.max_columns", None)
 +pd.set_option("display.max_rows", None)
 +pd.set_option("display.width", None)
 </code> </code>
  
Ligne 101: Ligne 107:
 <code python> <code python>
 df['name'] = df['name'].apply(lambda s: s.replace("_STARPU_", "").replace("FUT_", "")) df['name'] = df['name'].apply(lambda s: s.replace("_STARPU_", "").replace("FUT_", ""))
 +</code>
 +
 +
 +==== Minimum ligne par ligne de deux colonnes ====
 +
 +[[https://stackoverflow.com/questions/16989946/creating-an-element-wise-minimum-series-from-two-other-series-in-python-pandas|Source]]
 +
 +<code python>
 +pandas.concat([s1, s2], axis=1).min(axis=1)
 </code> </code>
  
Ligne 224: Ligne 239:
 df_starts.rename(columns={"Time start": "Time"}, inplace=True) df_starts.rename(columns={"Time start": "Time"}, inplace=True)
 </code> </code>
 +
 +Pour des colonnes qui n'avaient initialement pas de nom :
 +<code python>
 +df.columns = ["A", "B", "C"]
 +</code>
 +
 +
 +
 +==== Éclater une colonne textuelle en plusieurs colonnes ====
 +
 +[[https://stackoverflow.com/questions/14745022/how-to-split-a-dataframe-string-column-into-two-columns|Source]]
 +
 +Si les valeurs de la colonne ''Configuration'' sont de la forme ''baseline.C.openmpi.linear.1'' :
 +<code python>
 +df[['Type', 'Size', 'MPI', 'Coll', 'Iter']] = df["Configuration"].str.split('.', expand=True)
 +</code>
 +
  
  
Ligne 307: Ligne 339:
 0    12 13 0    12 13
 1    14 15 1    14 15
 +</code>
 +
 +
 +
 +==== Fonction inverse d'un percentile ====
 +
 +Pour connaître quelle est la proportion de valeurs qui sont inférieures à ''x'' ([[https://stackoverflow.com/questions/26489134/whats-the-inverse-of-the-quantile-function-on-a-pandas-series|source]]) :
 +
 +<code python>
 +(df < x).astype(int).mean()
 </code> </code>
  • python/pandas.1690555729.txt.gz
  • Dernière modification : 2023/07/28 16:48
  • de phsw