dom_2108
dom_2108

Reputation: 49

Sorting columns in dataframes with panda

I’m completely new to python so I don’t have a clue where to start but I have an excel spreadsheet table with 10,000 pieces of data about the google App Store. I’ve imported panda and imported the csv into python aswell. There are 5 columns including name, genre, rating, price, downloads. I need to sort the data frame from highest price first and descending down. Anyone have any simple solutions?

Upvotes: 0

Views: 53

Answers (2)

Deven
Deven

Reputation: 741

Python has a very good API documentation for pandas. You can explore the sort_values method for a DataFrame here.

Note, by default it places NA values at the last, sorts in ascending order and inplace = False (that is return a new df). For your problem, you can use

import pandas as pd
df = pd.read_csv('your_filename.csv')
df.sort_values(by='price', ascending=False, inplace=True)

Upvotes: 1

Aditya Mishra
Aditya Mishra

Reputation: 1875

Try this -

import pandas as pd
df = pd.read_csv('google-play-store.csv')
df.sort_values(by=['price'], ascending=False)

Upvotes: 1

Related Questions