{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"df=pd.DataFrame(data=np.array([['A','A','B','B','B'],['yes','no','yes','no','yes'],[1,1,1,1,1]]).T,columns=['letter','yn','ones'])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" letter | \n",
" yn | \n",
" ones | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" A | \n",
" yes | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" A | \n",
" no | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" B | \n",
" yes | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" B | \n",
" no | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" B | \n",
" yes | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" letter yn ones\n",
"0 A yes 1\n",
"1 A no 1\n",
"2 B yes 1\n",
"3 B no 1\n",
"4 B yes 1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" letter | \n",
" yn | \n",
" ones | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" A | \n",
" yes | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" letter yn ones\n",
"0 A yes 1"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[(df.letter=='A')&df.yn.str.contains('y')]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (py39)",
"language": "python",
"name": "py39"
},
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}