Skip to content

Instantly share code, notes, and snippets.

merged = pd.merge(df1, df2, on='C1', how='left')
# Grouping by 'C1' and checking for multiple occurrences
grouped = merged.groupby('C1')
# Creating the new DataFrame with custom values for multiple occurrences
df3 = pd.DataFrame(columns=merged.columns)
for name, group in grouped:
if len(group) > 1:
df3 = df3.append({col: 'multiple' if col == 'C2' else 'MULTIPLE' for col in merged.columns}, ignore_index=True)
import pandas as pd
# Texte initial
texte = 'prix\n100\nnombre\n2'
# Diviser le texte en lignes
lignes = texte.split('\n')
# Initialiser des listes vides pour stocker les données
colonnes = []
/* Déclaration de la macro variable */
%let date_sas = '01JAN2023'd;
/* Extraction de v1 */
data _null_;
/* Conversion de la date en format numérique YYYYMM */
v1 = year(&date_sas.) * 100 + month(&date_sas.);
call symputx('v1', v1);
run;
@hdary85
hdary85 / Dax
Created February 1, 2024 05:04
Taux_Variation_MNE =
CALCULATE(
(
SUMX(
VALUES('PBI'[MNE]),
(CALCULATE(SUM('PBI'[Montant]), 'PBI'[Semestre] = 2) -
CALCULATE(SUM('PBI'[Montant]), 'PBI'[Semestre] = 1)) /
CALCULATE(SUM('PBI'[Montant]), 'PBI'[Semestre] = 1)
)
),
@hdary85
hdary85 / Dax
Created February 1, 2024 04:52
Dax
Taux_Variation_Produit =
VAR Ventes_Semestre1 = CALCULATE(SUM('TableVentess'[Ventes]), 'TableVentess'[Semestre] = 1)
VAR Ventes_Semestre2 = CALCULATE(SUM('TableVentess'[Ventes]), 'TableVentess'[Semestre] = 2)
VAR Ventes_Produit = CALCULATE(SUM('TableVentess'[Ventes]), ALLEXCEPT('TableVentess', 'TableVentess'[Produit]))
RETURN
IF(ISBLANK(Ventes_Semestre1) || ISBLANK(Ventes_Semestre2) || Ventes_Semestre1 = 0, BLANK(), (Ventes_Semestre2 - Ventes_Semestre1) / Ventes_Produit)
@hdary85
hdary85 / sas
Last active January 23, 2024 02:40
%macro CalculTrimestre(dateDebutTrimestre);
/* Format the dateDebutTrimestre variable as a date */
%let dateDebutTrimestre = %sysfunc(inputn(&dateDebutTrimestre, date9.));
/* Étape 1: Filtrer les clients dont l'anniversaire est dans le trimestre fourni */
proc sql;
create table ClientsAnniversaire as
select *
from VotreTable
@hdary85
hdary85 / qt
Created January 23, 2024 01:58
from PyQt5.QtWidgets import QApplication, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QPushButton, QWidget, QLineEdit, QMessageBox, QLabel
class NestedDictManager(QApplication):
def __init__(self, original_data):
super(NestedDictManager, self).__init([])
self.original_data = original_data.copy()
self.data = original_data.copy()
self.tree = QTreeWidget()
@hdary85
hdary85 / widg2
Last active January 23, 2024 01:45
import ipywidgets as widgets
from IPython.display import display
class NestedDictManagerJupyter:
def __init__(self, original_data):
self.original_data = original_data
self.data = original_data.copy()
self.accordion = widgets.Accordion(selected_index=None)
self.accordion.observe(self.update_selected_item, names='selected_index')
@hdary85
hdary85 / Widget
Created January 23, 2024 00:54
Widget
import ipywidgets as widgets
from IPython.display import display
def update_nested_dict(nested_dict, keys, new_value):
current_dict = nested_dict
for key in keys[:-1]:
current_dict = current_dict[key]
current_dict[keys[-1]] = new_value
def display_and_update_widgets(nested_dict):
@hdary85
hdary85 / Streamlit
Last active January 23, 2024 00:21
# Save the Streamlit code in a separate file, e.g., my_streamlit_app.py
# my_streamlit_app.py
import streamlit as st
def update_nested_dict(nested_dict, keys, new_value):
current_dict = nested_dict
for key in keys[:-1]:
current_dict = current_dict[key]
current_dict[keys[-1]] = new_value