我试图通过划分两个现有的列来创建新列,对降序排列在新列上的csv进行排序,然后打印出新的前十行。这是我到目前为止所拥有的。
import pandas as pd
import numpy as np
import csv
#loading the csv file
df = pd.read_csv('tmdb-movies.csv')
#Create column for calculated profitability
df['Profitability'] = df['revenue_adj'] / df['budget_adj']
df = sorted(df['Profitability'], key=float)
df.head(10)
我可以计算“利润”列,但似乎无法对其进行排序。
答案 0 :(得分:0)
尝试:
df = df.sort_values(by='Profitability', ascending=False)
答案 1 :(得分:0)
只需在上面的答案中添加asdending = False ...
<head>
<script>
function clickHandler(){
document.getElementById('para1').style.border =
document.querySelectorAll('#size, #style, #colour).value;
}
</script>
</head>
<body>
<h1>Introduction to JavaScript</h1>
<p id="para1">JavaScript is also known as ECMAScript.</p>
<p>Size:
<input type="text" id="size">
</p>
<p>Style:
<input type="text" id="style">
</p>
<p>Colour:
<input type="text" id="colour">
</p>
<button type="button" onclick="clickHandler()" value="Change style">Change style</button>
现在在移动设备上。不确定是否可以将.head(10)添加到上述代码的末尾,或者是否必须创建新的数据框...
df.sort_values(by = ‘Profitability’, ascending = False)