Pandas common data cleansing (1)

Source: Internet
Author: User

Data Source acquisition:

Https://www.kaggle.com/datasets

 

1,

Look at the some basic stats for the ‘imdb_score’ column: data.imdb_score.describe()Select a column: data[‘movie_title’]Select the first 10 rows of a column: data[‘duration’][:10]Select multiple columns: data[[‘budget’,’gross’]]Select all movies over two hours long: data[data[‘duration’] > 120]

 

data.country = data.country.fillna(‘’)data.duration = data.duration.fillna(data.duration.mean())data = pd.read_csv(‘movie_metadata.csv’, dtype={title_year: str})data[‘movie_title’].str.upper()Similarly, to get rid of trailing whitespace:data[‘movie_title’].str.strip()data = data.rename(columns = {‘title_year’:’release_date’, ‘movie_facebook_likes’:’facebook_likes’})

 

Discard all items with Nan. dropna () discards the row data where all elements are Nan. dropna (how = 'all') discards the data column where all elements are Nan. dropna (axis = 1, how = 'all') # axis = 0 rows, = 1 column only retains rows with at least three non-nan values. dropna (thresh = 3)

 

Pandas common data cleansing (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.