共計(jì) 382 個(gè)字符,預(yù)計(jì)需要花費(fèi) 1 分鐘才能閱讀完成。
在 Python 中讀取 CSV 數(shù)據(jù)并指定行列可以使用 pandas 庫(kù)。下面是一個(gè)簡(jiǎn)單的示例:
import pandas as pd
# 讀取 CSV 文件
data = pd.read_csv('data.csv')
# 指定行列
# 獲取第一行數(shù)據(jù)
first_row = data.iloc[0]
# 獲取第一列數(shù)據(jù)
first_column = data.iloc[:, 0]
# 獲取指定行列數(shù)據(jù)
specific_data = data.iloc[0, 2]
print(first_row)
print(first_column)
print(specific_data)
在上面的示例中,data.iloc[0]
表示獲取第一行數(shù)據(jù),data.iloc[:, 0]
表示獲取第一列數(shù)據(jù),data.iloc[0, 2]
表示獲取第一行第三列的數(shù)據(jù)??梢愿鶕?jù)具體需求指定不同的行列。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完