Python |パンダSeries.str.endswith()

パンダendswith() —これは、シリーズまたは endswith()データ内のテキストデータを検索してフィルタリングするための別の方法です。このメソッドは、Pythonメソッド

例1:ブールシリーズのリターン
この例では、 str.endswith() を使用して、アイテムの行末に「e」が付いているかどうかを大学の列で確認します。行末に「e」が表示されているインデックス位置でtrueと評価される論理系列が返されます。 str.lower()は、データがとにかく可能性があるため、endwith()の前に呼び出されます。

< td class = "code">

#import pandas module

import pandas as pd


#URLからCSVファイルを読み取る

データ = pd.read_csv( " https://media.python.engineering/wp-content/uploads /nba.csv "


#検索する文字列行の終わり

検索 = "e"


#boolean series NaNの代わりにFalseを返します

bool_series = データ[" College " ]。 str 。低い () 。 str 。 extendswith(検索)


#論理系列表示
bool_series

< b>出力:
出力画像に示されているように、boolシリーズは、College列が「e」で終わるインデックス位置でTrueです。これは、元のデータフレーム画像を見て比較することもできます。

例2NULL値の処理

データ分析の最も重要な部分は、null値の処理です。上の出力画像でわかるように、ブールランにはNaNがあり、College列の値は空白またはNaNでした。この論理行がデータフレームに渡されると、エラーがスローされます。したがって、NaN値は naパラメータを使用して処理する必要があります。文字列に設定することもできますが、boolシリーズは適切な値を渡して返すために使用されるため、Boolにのみ設定する必要があります。
この例では、 naはFalseです。したがって、College列がNullの場合、BoolシリーズはNaNではなくFalseを格納します。次に、系列がデータフレームに戻され、真の値のみが表示されます。

#pandas module import

import pandas as pd


#URLからCSVファイルを読み取る

データ = pd.read_csv( " https://media.python.engineering/wp-content/uploads/nba.csv "


#行末で検索する文字列 < / p>

検索 = "e"


#booleanシリーズはFalで返されますNaNの代わりにse

bool_series = data [ "College" ]。 str 。低い ()。 str 。 extendswith(search、na = False


#フィルタリングされたデータフレームを表示する
data [bool_series]

出力:
出力画像に示されているように、データフレームには、College列の最後の行に「e」がある行があります。 naパラメータがFalseに設定されているため、NaN値は表示されません。

この記事が問題の解決に役立つことを願っています。 Python |パンダSeries.str.endswith() とは別に、他の Python functions 関連のトピックを確認してください。

Python で上達したいですか?  最高の Python オンライン コース 2023 のレビューをご覧ください。 データ サイエンスに興味がある場合は、R でプログラミングを学ぶ方法も確認してください。

ちなみに、この資料は他の言語でも利用できます:



Schneider Ungerschaft

Berlin | 2023-03-30

説明ありがとうございました 何時間かPython |パンダSeries.str.endswith()で詰まってました、やっと出来ました🤗。. それが最良の方法であるかどうかはわかりません

Angelo Porretti

Tallinn | 2023-03-30

シンプルにまとめられていて分かりやすい。シェアしてくださってありがとうございます。Python |パンダSeries.str.endswith()やPython functionsの問題はいつも私の弱点でした😁。. 卒論で使わせていただきます

Xu Lehnman

Warsaw | 2023-03-30

私はコーディングの面接の準備をしていました、これを明確にしてくれてありがとう - PythonのPython |パンダSeries.str.endswith()は最も単純なものではありません. それが最良の方法であるかどうかはわかりません

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically