DataFrame 内の文字列ですが、dtype はオブジェクトです
一部のユーザーは、特定の列に「dtype オブジェクト」が表示されている Pandas DataFrame に遭遇しました。明示的に文字列に変換した後でも、それらの列内のすべての項目は文字列です。この動作を理解するには、Pandas と NumPy のデータ型の性質を詳しく調べる必要があります。Pandas の基礎となるライブラリである
NumPy は、データ型を int64、float64、および object として特徴付けます。 「オブジェクト」dtype は、NumPy 配列内の要素が、整数や浮動小数点の場合のように、バイト単位での均一な固定サイズではないことを示します。
文字列の場合、その長さは変化するため、直接格納されます。配列内の文字列バイトは実用的ではありません。代わりに、Pandas は文字列オブジェクトへのポインターを格納する「オブジェクト配列」を利用します。このアプローチは、文字列を含む列に対して dtype がオブジェクトである理由を説明します。
次の例を考えてみましょう:
import numpy as np import pandas as pd # Create a NumPy array of integers int_array = np.array([1, 2, 3, 4], dtype=np.int64) # Create a NumPy array of strings object_array = np.array(['a', 'b', 'c', 'd'], dtype=np.object) # Convert the object array to pandas DataFrame df = pd.DataFrame({'INTS': int_array, 'STRINGS': object_array}) # Check the data types print(df.dtypes) # Print the lengths of the first item in each column print(len(df['INTS'].iat[0])) print(len(df['STRINGS'].iat[0]))
出力は次のようになります:
INTS int64 STRINGS object dtype: object 1 1
可能な限りすべての要素が 8 バイトの整数であるため、「INTS」列の dtype は int64 です。 「STRINGS」列は、その要素が文字列オブジェクトへのポインタであるため、オブジェクトの dtype を持ちます。出力からわかるように、各文字列の長さは異なります。
以上が文字列を含む Pandas DataFrame 列に文字列に変換した後でも「dtype object」が表示されるのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。
