Skip to content

Commit

Permalink
feat(Python): Add Convert string boolean to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Jul 25, 2023
1 parent f4a61ae commit 8a20fb8
Showing 1 changed file with 241 additions and 0 deletions.
241 changes: 241 additions & 0 deletions Python/Python_Convert_string_boolean_to_boolean.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "f07197a2-e3e0-4a1d-9fcb-384b97b0c705",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "markdown",
"id": "03d78797-4963-40a9-999b-e3febc4b0f24",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Python - Convert string boolean to boolean"
]
},
{
"cell_type": "markdown",
"id": "d02b4711-6575-4491-a0aa-b7928b3aab37",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #python #string #boolean #convert #type #data"
]
},
{
"cell_type": "markdown",
"id": "e28ab09c-00af-4a58-8ce7-49e773d3bbed",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)"
]
},
{
"cell_type": "markdown",
"id": "611d1150-cebd-44a3-aa77-0c522d5e2692",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-07-25 (Created: 2023-07-25)"
]
},
{
"cell_type": "markdown",
"id": "7b8b3d9c-90f9-40de-a946-1af9c5229dc2",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook will show how to convert a string boolean to a boolean type in Python. It is usefull for data cleaning and data manipulation."
]
},
{
"cell_type": "markdown",
"id": "55533498-504c-4776-b67f-f7bf80d7a687",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n- [Python - Convert string boolean to boolean](https://www.w3schools.com/python/python_booleans.asp)\n- [Python - Type conversion](https://www.programiz.com/python-programming/type-conversion-and-type-casting)"
]
},
{
"cell_type": "markdown",
"id": "172bf187-a3b8-4b00-b1b7-4a8c62f62a55",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "7b4afe76-77f4-4bb0-b0cb-88607150ea66",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "829817d4-7f3c-4e24-a49f-2707b8542270",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Import libraries\nimport ast",
"outputs": []
},
{
"cell_type": "markdown",
"id": "cea15f4f-7f7f-4c3d-a1b2-9104b08a9a81",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup Variables\n- `string_boolean`: string boolean to convert"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99d36797-19b4-4fb9-be17-6b7b71503d0b",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Setup variables\nstring_boolean = \"True\"",
"outputs": []
},
{
"cell_type": "markdown",
"id": "5788a56a-70d5-4543-876b-0b2e05f88076",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "1aa1f5af-9762-4d27-bae6-28e6dd980a6f",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Convert string boolean to boolean"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfdf07ac-f9ad-43a6-a09d-7c8bce47bb39",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Convert string boolean to boolean\nboolean = ast.literal_eval(string_boolean)",
"outputs": []
},
{
"cell_type": "markdown",
"id": "e44936c4-6424-404c-9a42-ff83a10b1f27",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "f9702a0b-eedf-4e15-9829-fa50a519ec89",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4d1fe38-6bb6-4610-b082-b496a0258de6",
"metadata": {
"papermill": {},
"tags": []
},
"source": "# Display result\nprint(boolean)",
"outputs": []
},
{
"cell_type": "markdown",
"id": "c81ca880-d0b4-499d-84ad-1fd5c26d9bb2",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 8a20fb8

Please sign in to comment.