Python CSV: Specify Rows & Columns with Pandas
You can use the pandas library in Python to read CSV data and specify rows and columns. Here is a simple example:
import pandas as pd
# 读取CSV文件
data = pd.read_csv('data.csv')
# 指定行列
# 获取第一行数据
first_row = data.iloc[0]
# 获取第一列数据
first_column = data.iloc[:, 0]
# 获取指定行列数据
specific_data = data.iloc[0, 2]
print(first_row)
print(first_column)
print(specific_data)
In the example above, data.iloc[0] refers to getting the first row of data, data.iloc[:, 0] refers to getting the first column of data, and data.iloc[0, 2] refers to getting the data in the first row and third column. Different rows and columns can be specified based on specific needs.