0

I have a big matrix import for one .csv more than 50.000 lines.

I am working with panda and numpy, the matrix is a film data base, I would like to sort the matrix by budget and see for example 10 first line showing all columns for this matrix.

Example: Sort by revenue, this is my objective.

IMDb_data[['film', 'budget', 'revenue','vote_average','cast']].head(3)

film    budget  revenue   vote_average ..... cast   director    homepage
J.Park  100000    150          5       .....  AAA      BBB      CCC.com
Sun     50000     75           4       .....  AAA      BBB      CCC.com
Night    2000     50           3       .....  AAA      BBB      CCC.com

Code use for import the IMDb_data:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
IMDb_data= pd.read_csv('tmdb-movies.csv')
0

2 Answers 2

1

You are looking for the sort_values method, you can precise by which column, and the order (ascending or descending)

df.sort_values(by='budget', ascending=False)

For more keywords, you can check out the official documentation

by is taking either a string (to sort with one column) or a list of string to sort by lexicographic order

ascending is taking a boolean (default True)

Sign up to request clarification or add additional context in comments.

Comments

0

IMDb_data.sort_values(by=['budget'], ascending=False) to sort by budget.

IMDb_data.sort_values(by=['revenue'], ascending=False) to sort by revenue.

pandas.DataFrame.sort_values

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.