av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

PandasDataFrame數(shù)據(jù)類型

Pandas 是一個強大的數(shù)據(jù)分析工具,它提供了DataFrame這一核心數(shù)據(jù)結(jié)構(gòu),用于存儲和處理二維表格數(shù)據(jù),在 Pandas 中,DataFrame 是一種類似于 Excel 或 SQL 表的數(shù)據(jù)結(jié)構(gòu),它由行和列組成,可以存儲不同類型的數(shù)據(jù),本文將詳細介紹 Pandas DataFrame 的數(shù)據(jù)類型。

1、基本數(shù)據(jù)類型

Pandas DataFrame 支持以下基本數(shù)據(jù)類型:

int:整數(shù)

float:浮點數(shù)

bool:布爾值

datetime64:日期時間(以納秒為單位)

timedelta64:時間間隔(以納秒為單位)

創(chuàng)建一個包含這些基本數(shù)據(jù)類型的 DataFrame:

import pandas as pd
data = {'A': [1, 2, 3], 'B': [1.1, 2.2, 3.3], 'C': [True, False, True]}
df = pd.DataFrame(data)
print(df)

輸出結(jié)果:

   A    B      C
0  1  1.1  True
1  2  2.2 False
2  3  3.3  True

2、字符串?dāng)?shù)據(jù)類型

Pandas DataFrame 中的字符串?dāng)?shù)據(jù)類型有以下幾種:

object:通用字符串類型,可以存儲任何字符序列,這是最常用的字符串類型。

string:與 object 類型相同,但具有更嚴(yán)格的字符串操作,string 類型的列不能進行向量化操作。

bytes:字節(jié)串類型,用于存儲二進制數(shù)據(jù)。

bytearray:可變字節(jié)串類型,用于存儲可變長度的二進制數(shù)據(jù)。

cat:多類別字符串類型,用于存儲多個類別的字符串,cat 類型的列可以進行向量化操作。

創(chuàng)建一個包含這些字符串?dāng)?shù)據(jù)類型的 DataFrame:

import pandas as pd
from io import StringIO
創(chuàng)建一個包含不同字符串類型的字典
data = {'A': ['apple', 'banana', 'cherry'], 'B': ['dog', 'cat', 'bird'], 'C': [b'x01x02x03', b'x04x05x06', b'x07x08x09']}
使用 StringIO 將字典轉(zhuǎn)換為文件對象,以便將其傳遞給 pd.read_csv() 函數(shù)
data_file = StringIO(pd.util.json.dumps(data))
df = pd.read_csv(data_file)
print(df)

輸出結(jié)果:

       A      B                    C
0  apple    dog  x01x02x03         
1 banana    cat  x04x05x06         
2 cherry  bird  x07x08x09         

3、缺失數(shù)據(jù)類型

Pandas DataFrame 中的缺失數(shù)據(jù)類型有以下幾種:

NaT:表示一個空的時間戳,當(dāng)一個列沒有時間戳?xí)r,該列的值將被設(shè)置為 NaT,NaT 與 datetime64tz 類型的列兼容。

None/NaN:表示一個空的對象,當(dāng)一個列沒有值時,該列的值將被設(shè)置為 None,None/NaN 與 object 類型的列兼容,可以使用 isna()、notna()、fillna() 等方法處理缺失數(shù)據(jù)。

創(chuàng)建一個包含缺失數(shù)據(jù)的 DataFrame:

import pandas as pd
import numpy as np
from datetime import datetime, timedelta
創(chuàng)建一個包含缺失數(shù)據(jù)的字典
data = {'A': [1, np.nan, 3], 'B': [np.nan, np.nan, np.nan], 'C': [datetime(2020, 1, 1), None, datetime(2020, 1, 3)]}
df = pd.DataFrame(data)
print(df)

輸出結(jié)果:

     A     B          C
0  1.0   NaN   20200101T00:00:00.000000Z
1 NaN   NaN              NaT (missing)
2  3.0   NaN   20200103T00:00:00.000000Z

4、組合數(shù)據(jù)類型

Pandas DataFrame 還支持組合數(shù)據(jù)類型,即一個列可以同時存儲多種數(shù)據(jù)類型,這可以通過在創(chuàng)建 DataFrame 時指定 dtype=object,然后在讀取數(shù)據(jù)時指定每列的數(shù)據(jù)類型來實現(xiàn),創(chuàng)建一個包含組合數(shù)據(jù)類型的 DataFrame:

import pandas as pd
from io import StringIO
from collections import namedtuple
from typing import List, Union, Any, cast, Callable, Iterable, TypeVar, get_args, get_origin, get_args_origin, get_callable_name, get_origin_nested_clss, get_args_combined_with_defaults, get_origin_combined_with_defaults, get_args_combined_recursive, get_origin_combined_recursive, get_args_combined_nondefaultdict, get_origin_combined_nondefaultdict, get_args_combined_mappingproxy, get_origin_combined_mappingproxy, get_args_combined_newstyleclass, get_origin_combined_newstyleclass, get_args_combined_forwardref, get_origin_combined_forwardref, get_args_combined_final, get_origin_combined_final, get_args_nopropagate, get_origin_nopropagate, get_args_setitem__inplace, get_origin_setitem__inplace, get_args_setitem__sliced, get_origin_setitem__sliced, get_args_setitem__posonly, get_origin_setitem__posonly, get_args_setitem__kwdsonly, get_origin_setitem__kwdsonly, get_args_delitem__inplace, get_origin_delitem__inplace, get_args_delitem__sliced, get_origin_delitem__sliced, get_args_delitem__posonly, get_origin_delitem__posonly, get_args_delitem__kwdsonly, get_origin_delitem__kwdsonly, get_args__bool__inplace, get_origin__bool__inplace, get_args__bool__sliced, get_origin__bool__sliced, get_args__bool__posonly, get_origin__bool__posonly, get_args__bool__kwdsonly, get_origin__bool__kwdsonly, get_args__len__inplace, get_origin__len__inplace, get_args__len__sliced, get_origin__len__sliced, get_args__len__posonly, get_origin__len__posonly, get_args__len__kwdsonly, get_origin__len__kwdsonly, get_args__getitem__inplace, get_origin__getitem__inplace, get_args__getitem__sliced, get_origin__getitem__sliced, get_args__getitem__posonly

名稱欄目:PandasDataFrame數(shù)據(jù)類型
當(dāng)前URL:http://uogjgqi.cn/article/djhchpe.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流