This article summarizes how to use pandas
Read csv
The specified line of the file 、 Column or element .
Last Modified Date: 2022 / 6 / 17
Reference resources 1, Use pandas
Read csv
Example data :
data = pd.read_csv(filepath_or_buffer=path, header=None)
print(data.columns)
# Int64Index([0, 1, 2], dtype='int64')
print(data.index.names)
# [None]
print(data)
# 0 1 2
# 0 ABCD NaN All
# 1 EFGH NaN All
# ...
# 1657 OPQR NaN All
# 1658 XYZN NaN All
[1659 rows x 3 columns]
Reference resources 2’ 3 Extract the specified column
loc
col_0 = data.loc[:, 0]
# To extract the first 1 Column content
# Other columns , And so on
pd.read_csv(..., usecols=[])
col_0 = pd.read_csv(filepath_or_buffer=path, header=None, usecols=[0])
# To ensure that the data read is correct , Can write excel, Then view the written data
# writer = pd.Excelwriter('./trial.xlsx')
# data.to_excel(writer, index = False, header = False)
# writer.save()
np.array
col_0 = np.array(data[0])
# The first 1 The column data will be stored as an array
Reference resources 2’ 3 Extract the specified column
pd.read_csv(..., nrows=10)
row_0to10 = pd.read_csv(filepath_or_buffer=path, header=None, nrows=10)
# Just before reading 10 That's ok
pd.read_csv(...,skiprows=9, nrows=5)
row_10to15 = pd.read_csv(..., skiprows=9, nrows=5)
# Ignore before 9 That's ok , Read on 5 That's ok
Python | Pandas | Reading, writing and preliminary processing of various types of files ︎
Python from csv Methods of reading and extracting data in ︎︎
pandas Read the specified line / Several operations of columns ︎︎