guest_blog — Published On September 5, 2020 and Last Modified On September 2nd, 2022
Beginner Data Exploration Pandas Programming Python

Introduction

Indexing and Selecting Data

  • Enables automatic and explicit data alignment.
  • Allows intuitive getting and setting of subsets of the data set.

 

# for getting values with a boolean array
print (df.loc['a']>0)

indexing and selecting data - .loc

print df.loc[:,'B']

indexing and selecting data - .loc

The query() Method

#creating dataframe of 10 rows and 3 columns
df4 = pd.DataFrame(np.random.rand(10, 3), columns=list('abc'))
df4

Image for post

Image for post

#with query()
df4.query('(x < b) & (b < c)')

Image for post

  • drop_duplicates: removes duplicate rows.
df5 = pd.DataFrame({'a': ['one', 'one', 'two', 'two', 'two'],
                    'b': ['x', 'y', 'x', 'y', 'x'],
                    'c': np.random.randn(5)})
df5

Image for post

df5.duplicated('a')

Image for post

df5.drop_duplicates('a')

Image for post

  1. Interesting 10 Machine Learning and Data Science Projects with Datasets
  2. Basic Understanding of NLP With Python

 

About the Author

Author

Amit Chauhan

I am a Research Scholar and a technical person with 4-year experience in R&D Electronics. Data Science enthusiastic

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

Top Resources