-
-
Save brandon-b-miller/4c98566065df3c30134c04d030654be8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "9392102f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0 4\n", | |
"1 11\n", | |
"2 <NA>\n", | |
"3 42\n", | |
"dtype: int64\n" | |
] | |
} | |
], | |
"source": [ | |
"import cudf\n", | |
"\n", | |
"df = cudf.DataFrame({\n", | |
" 'a': [1,cudf.NA,3, cudf.NA],\n", | |
" 'b': [4,5,cudf.NA, cudf.NA]\n", | |
"})\n", | |
"\n", | |
"def f(row):\n", | |
" x = row['a']\n", | |
" y = row['b']\n", | |
"\n", | |
" if x is cudf.NA and y is cudf.NA:\n", | |
" return 42\n", | |
"\n", | |
" elif x is cudf.NA:\n", | |
" return 11\n", | |
" \n", | |
" elif y is cudf.NA:\n", | |
" return cudf.NA\n", | |
" \n", | |
" else:\n", | |
" return x + y - 1\n", | |
" \n", | |
"result = df.apply(f, axis=1)\n", | |
"print(result)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"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.8.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment