import pandas as pd # 创建示例 DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [30, 25, 35], 'Salary': [50000, 60000, 45000] } df = pd.DataFrame(data) # 按照 'Age' 列升序排序 sorted_df = df.sort_values(by='Age', ascending=True) print("Original DataFrame:") print(df) print("\nSorted DataFrame:") print(sorted_df)
import pandas as pd # 创建示例 DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David'], 'Age': [30, 25, 35, 25], 'Salary': [50000, 60000, 45000, 55000] } df = pd.DataFrame(data) # 按照 'Age' 列升序,然后按照 'Salary' 列降序排序 sorted_df = df.sort_values(by=['Age', 'Salary'], ascending=[True, False]) print("Original DataFrame:") print(df) print("\nSorted DataFrame:") print(sorted_df)
标签:排序,df,Age,DataFrame,pd,print,多列 From: https://www.cnblogs.com/nicole-zhang/p/17614006.html