1. Home
  2. Docs
  3. Python-DataScience
  4. Data Manipulate with Pandas
  5. Manipulation with Index

Manipulation with Index

Efficiently manipulate data with index operation

利用index快速定位,排序

高阶应用举例

# 利用&命令快速生成符合2个条件的bool-type index array
# 传入索引得到row
# 因为python数据存储格式包含两部分(data_type, data_values)
# 利用.index.values读取row的index的值
# 由此也可以看出index的类型是ndarray
df_628[(df_628['总推力(kN)']==15700)&(df_628['环号']==90)].index.values

.all()和.any()命令

np.array.any()是操作,任意一个元素为True,输出为True。
np.array.all()是操作,所有元素为True,输出为True

arr1 = np.arange(10)
arr2 = np.arange(10)
print((arr1 == arr2).all())
#result:True

Dict 与 DataFrame异同

dict的储存为(type, keys, values)

Erase Duplicates

# return bool list tells if each element is duplicated

df.duplicated()

# remove duplicated elements, leave unique ones only

df.drop_duplicates()

 {eliminate duplicates-csdn}

set index

 pd.set_index(keys=[KEYS_of_columns_to_be_the_new_index])

reference:

 

{pandas_index_setting-CSDN}

Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.