2025.42 changes
This commit is contained in:
11
source/pandas/01-pandas-files/.pandasrc.ini
Normal file
11
source/pandas/01-pandas-files/.pandasrc.ini
Normal file
@@ -0,0 +1,11 @@
|
||||
[display]
|
||||
width = 200
|
||||
max_colwidth = 25
|
||||
max_columns = 20
|
||||
min_rows = 20
|
||||
precision = 3
|
||||
expand_frame_repr = True
|
||||
memory_usage = True
|
||||
|
||||
[display.html]
|
||||
border = 4
|
||||
7
source/pandas/01-pandas-files/03-csv-catalog.py
Normal file
7
source/pandas/01-pandas-files/03-csv-catalog.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import pandas as pd
|
||||
from pandas import configfile
|
||||
|
||||
|
||||
configfile.load()
|
||||
df = pd.read_csv("../data/csv/demo-file.csv", encoding="1252", header=None)
|
||||
print(df)
|
||||
BIN
source/pandas/data/datasets-csv-excel.zip
Normal file
BIN
source/pandas/data/datasets-csv-excel.zip
Normal file
Binary file not shown.
@@ -2,7 +2,7 @@ import pandas as pd
|
||||
from matplotlib import use, pyplot
|
||||
|
||||
# Utiliser tkinter
|
||||
use("TkAgg")
|
||||
# use("TkAgg")
|
||||
pyplot.style.use('ggplot')
|
||||
pyplot.rcParams["font.family"] = "Cabin"
|
||||
|
||||
|
||||
14
source/plotting/charts/plotly_figure_bar.py
Normal file
14
source/plotting/charts/plotly_figure_bar.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.DataFrame(data={"label": ["Citron", "Pomme", "Mangue"], "price": [1.99, 3.97, 6.8]})
|
||||
figure = Figure(
|
||||
data=[Bar(x=df["label"], y=df["price"])],
|
||||
layout={
|
||||
"font": {"family": "Cabin", "size": 20},
|
||||
"title": "Prix au kilo",
|
||||
}
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
20
source/plotting/charts/plotly_figure_multiaxis.py
Normal file
20
source/plotting/charts/plotly_figure_multiaxis.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["pomme", "poire", "banane", "pêche"],
|
||||
"price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200]
|
||||
})
|
||||
figure = Figure([
|
||||
Bar(name="Prix", x=data["product"], y=data["price"], yaxis="y1", offsetgroup=1, texttemplate="%{y:.2f}€"),
|
||||
Bar(name="Poids", x=data["product"], y=data["wpu"], yaxis="y2", offsetgroup=2, texttemplate="%{y:.2f}g"),
|
||||
])
|
||||
# Afficher le dernier graphique généré
|
||||
figure.layout.update({
|
||||
"template": "seaborn",
|
||||
"title": "Prix et poids unitaires",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"yaxis1": {"title": "Prix (€)", "color": "red"},
|
||||
"yaxis2": {"title": "Poids (g)", "overlaying": "y1", "side": "right"}
|
||||
})
|
||||
figure.show(renderer="browser")
|
||||
27
source/plotting/charts/plotly_figure_pie.py
Normal file
27
source/plotting/charts/plotly_figure_pie.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Pie
|
||||
from plotly.colors import qualitative
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["oignon", "carotte", "pomme", "poire", "radis", "tomate"],
|
||||
"category": ["légume", "légume", "fruit", "fruit", "légume", "fruit"],
|
||||
"origin": ["Espagne", "France", "France", "France", "France", "Espagne"],
|
||||
"price": [1.69, 2.49, 2.99, 1.79, 1.29, 2.99]
|
||||
})
|
||||
figure = Figure(
|
||||
data=[Pie(
|
||||
values=data["price"],
|
||||
labels=data["product"].str.title(),
|
||||
customdata=data[["category", "origin"]],
|
||||
title="Prix",
|
||||
textinfo="label+value",
|
||||
texttemplate="<b>%{label}</b><br>%{value:.2f}€<br><em>%{customdata[0]}</em><br>%{customdata[1]}",
|
||||
insidetextorientation="tangential")
|
||||
],
|
||||
layout={
|
||||
"template": "seaborn",
|
||||
"font": {"family": "Cabin", "size": 20},
|
||||
"title": "Prix au kilo",
|
||||
"piecolorway": qualitative.Prism
|
||||
})
|
||||
figure.show(renderer="browser")
|
||||
29
source/plotting/charts/plotly_figure_sunburst.py
Normal file
29
source/plotting/charts/plotly_figure_sunburst.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Sunburst
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.DataFrame(data={
|
||||
"continent": ["Europe", "Europe", "Europe", "Europe", "Europe", "Europe", "Europe", "Asia", "Asia"],
|
||||
"country": ["France", "France", "Spain", "Spain", "England", "England", "England", "China", "China"],
|
||||
"city": ["Montpellier", "Bordeaux", "Madrid", "Valencia", "London", "Manchester", "Bristol", "Beijing", "Shanghai"],
|
||||
"sales": [150_000, 127_000, 97_200, 137_250, 200_000, 180_000, 150_000, 120_000, 140_000]
|
||||
})
|
||||
# Create a path column
|
||||
PATH: list[str] = ["continent", "country", "city"]
|
||||
COLUMNS: list[str] = [None] * (len(PATH) - 2) + ["parent", "child"]
|
||||
|
||||
rollups = []
|
||||
base = df.groupby(PATH).sum(numeric_only=True)
|
||||
for level in range(len(PATH)):
|
||||
rollup = base.groupby(None, level=list(range(level + 1))).sum()
|
||||
rollup = rollup.reset_index(list(range(level + 1)), names=COLUMNS[-level - 1:])
|
||||
rollups.append(rollup)
|
||||
rollups = pd.concat(rollups, axis=0)
|
||||
|
||||
sb = Sunburst(labels=rollups["child"], parents=rollups["parent"], values=rollups["sales"], textinfo="label+value+percent parent", texttemplate="%{label}<br>%{value:,.2f}€", branchvalues="total")
|
||||
fig: Figure = Figure(sb, layout={
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"margin": {"l": 0, "r": 0, "b": 0, "t": 0}
|
||||
})
|
||||
fig.show(renderer="browser")
|
||||
@@ -17,5 +17,9 @@ if __name__ == '__main__':
|
||||
})
|
||||
plot = sunburst(df, path=["country", "city"], values="sales", title="Sales by country and city", template="ggplot2",
|
||||
color_discrete_sequence=plotly.colors.qualitative.Dark2)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
sb = next(plot.select_traces(row=0, col=0))
|
||||
sb.textinfo="label+percent parent"
|
||||
# sb.texttemplate="%{label}<br>%{value:.2f}€"
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}, "showlegend": True})
|
||||
# plot.update_traces(textinfo="label+percent parent", texttemplate="%{label}<br>%{value:.2f}€")
|
||||
plot.show(renderer="browser")
|
||||
|
||||
9
source/plotting/charts/plotly_template_select.py
Normal file
9
source/plotting/charts/plotly_template_select.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from plotly.express import bar
|
||||
import pandas as pd
|
||||
|
||||
data = pd.DataFrame({
|
||||
"product": ["stylo", "clavier", "souris", "écran"],
|
||||
"price": [1.99, 15.99, 8.99, 129.99],
|
||||
})
|
||||
figure = bar(data, x="product", y="price", title="Prix", template="seaborn")
|
||||
figure.show(renderer="browser")
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
@@ -1,163 +0,0 @@
|
||||
amqp==5.2.0
|
||||
anyio==4.3.0
|
||||
argon2-cffi==23.1.0
|
||||
argon2-cffi-bindings==21.2.0
|
||||
arrow==1.3.0
|
||||
asttokens==2.4.1
|
||||
async-lru==2.0.4
|
||||
attrs==23.2.0
|
||||
Babel==2.14.0
|
||||
beautifulsoup4==4.12.3
|
||||
billiard==4.2.0
|
||||
bleach==6.1.0
|
||||
blinker==1.8.1
|
||||
cairocffi==1.7.0
|
||||
celery==5.4.0
|
||||
certifi==2024.2.2
|
||||
cffi==1.16.0
|
||||
charset-normalizer==3.3.2
|
||||
click==8.1.7
|
||||
click-didyoumean==0.3.1
|
||||
click-plugins==1.1.1
|
||||
click-repl==0.3.0
|
||||
cloudpickle==3.0.0
|
||||
comm==0.2.2
|
||||
contexttimer==0.3.3
|
||||
contourpy==1.2.1
|
||||
cycler==0.12.1
|
||||
dash==2.16.1
|
||||
dash-core-components==2.0.0
|
||||
dash-html-components==2.0.0
|
||||
dash-table==5.0.0
|
||||
dask==2024.6.2
|
||||
dask-expr==1.1.6
|
||||
debugpy==1.8.1
|
||||
decorator==5.1.1
|
||||
defusedxml==0.7.1
|
||||
distributed==2024.6.2
|
||||
duckdb==1.0.0
|
||||
et-xmlfile==1.1.0
|
||||
executing==2.0.1
|
||||
fastjsonschema==2.19.1
|
||||
Flask==3.0.3
|
||||
fonttools==4.51.0
|
||||
fqdn==1.5.1
|
||||
fsspec==2024.6.1
|
||||
greenlet==3.0.3
|
||||
h11==0.14.0
|
||||
httpcore==1.0.5
|
||||
httpx==0.27.0
|
||||
idna==3.7
|
||||
importlib_metadata==7.1.0
|
||||
ipykernel==6.29.4
|
||||
ipython==8.24.0
|
||||
ipywidgets==8.1.2
|
||||
isoduration==20.11.0
|
||||
itsdangerous==2.2.0
|
||||
jedi==0.19.1
|
||||
Jinja2==3.1.3
|
||||
json5==0.9.25
|
||||
jsonpointer==2.4
|
||||
jsonschema==4.22.0
|
||||
jsonschema-specifications==2023.12.1
|
||||
jupyter==1.0.0
|
||||
jupyter-console==6.6.3
|
||||
jupyter-events==0.10.0
|
||||
jupyter-lsp==2.2.5
|
||||
jupyter_client==8.6.1
|
||||
jupyter_core==5.7.2
|
||||
jupyter_server==2.14.0
|
||||
jupyter_server_terminals==0.5.3
|
||||
jupyterlab==4.1.8
|
||||
jupyterlab_pygments==0.3.0
|
||||
jupyterlab_server==2.27.1
|
||||
jupyterlab_widgets==3.0.10
|
||||
kiwisolver==1.4.5
|
||||
kombu==5.3.7
|
||||
locket==1.0.0
|
||||
MarkupSafe==2.1.5
|
||||
matplotlib==3.8.4
|
||||
matplotlib-inline==0.1.7
|
||||
mistune==3.0.2
|
||||
msgpack==1.0.8
|
||||
nbclient==0.10.0
|
||||
nbconvert==7.16.4
|
||||
nbformat==5.10.4
|
||||
nest-asyncio==1.6.0
|
||||
notebook==7.1.3
|
||||
notebook_shim==0.2.4
|
||||
numpy==1.26.4
|
||||
openpyxl==3.1.2
|
||||
overrides==7.7.0
|
||||
packaging==24.0
|
||||
pandas==2.2.2
|
||||
pandas-stubs==2.2.2.240603
|
||||
pandocfilters==1.5.1
|
||||
parso==0.8.4
|
||||
partd==1.4.2
|
||||
pexpect==4.9.0
|
||||
pillow==10.3.0
|
||||
platformdirs==4.2.1
|
||||
plotly==5.21.0
|
||||
polars==0.20.31
|
||||
prometheus_client==0.20.0
|
||||
prompt-toolkit==3.0.43
|
||||
psutil==5.9.8
|
||||
psycopg==3.2.1
|
||||
ptyprocess==0.7.0
|
||||
pure-eval==0.2.2
|
||||
pyarrow==16.1.0
|
||||
pycparser==2.22
|
||||
Pygments==2.17.2
|
||||
pylibmc==1.6.3
|
||||
pyparsing==3.1.2
|
||||
PySide6==6.7.0
|
||||
PySide6_Addons==6.7.0
|
||||
PySide6_Essentials==6.7.0
|
||||
python-dateutil==2.9.0.post0
|
||||
python-json-logger==2.0.7
|
||||
pytz==2024.1
|
||||
PyYAML==6.0.1
|
||||
pyzmq==26.0.2
|
||||
qtconsole==5.5.1
|
||||
QtPy==2.4.1
|
||||
redis==5.0.4
|
||||
referencing==0.35.0
|
||||
requests==2.31.0
|
||||
retrying==1.3.4
|
||||
rfc3339-validator==0.1.4
|
||||
rfc3986-validator==0.1.1
|
||||
rpds-py==0.18.0
|
||||
Send2Trash==1.8.3
|
||||
setuptools==69.5.1
|
||||
shiboken6==6.7.0
|
||||
six==1.16.0
|
||||
sniffio==1.3.1
|
||||
sortedcontainers==2.4.0
|
||||
soupsieve==2.5
|
||||
SQLAlchemy==2.0.31
|
||||
stack-data==0.6.3
|
||||
tblib==3.0.0
|
||||
tenacity==8.2.3
|
||||
terminado==0.18.1
|
||||
tinycss2==1.3.0
|
||||
toolz==0.12.1
|
||||
tornado==6.4
|
||||
traitlets==5.14.3
|
||||
types-python-dateutil==2.9.0.20240316
|
||||
types-pytz==2024.1.0.20240417
|
||||
typing_extensions==4.11.0
|
||||
tzdata==2024.1
|
||||
Unidecode==1.3.8
|
||||
uri-template==1.3.0
|
||||
urllib3==2.2.1
|
||||
vine==5.1.0
|
||||
wcwidth==0.2.13
|
||||
webcolors==1.13
|
||||
webencodings==0.5.1
|
||||
websocket-client==1.8.0
|
||||
Werkzeug==3.0.2
|
||||
widgetsnbextension==4.0.10
|
||||
XlsxWriter==3.2.0
|
||||
zict==3.0.0
|
||||
zipp==3.18.1
|
||||
Reference in New Issue
Block a user