函数dataframe,该函数以字典为输入并从字典中创建数据,对字典进行排序。
使用说明
1. Create a dataframe with the input dictionary
2. Columns should be Name Age
3. Print "Before Sorting"
4. Print a Newline
5. Print the dataframe before sorting.
Note: Printing the dataframe must not contain index.
6. Print a Newline
7. Sort the dataframe in ascending order based on Age column
8. Print "After Sorting"
9. Print a Newline
10. Print the dataframe after sorting. Note: Printing the dataframe must not contain index.▾样例0
样本输入
威廉:42,乔治:10,约瑟夫:22,亨利:15,塞缪尔:32,大卫:18
样本输出
分拣前
名称时代
威廉42
乔治。10
约瑟夫。22
亨利。15
塞缪尔。32
大卫。18
分拣后
名字。年龄
乔治。10
亨利。15
大卫。18
约瑟夫。22
塞缪尔。32
威廉。42
发布于 2022-08-18 01:00:03
希望这能有所帮助。
def dict_to_df(key, value):
my_dict = {key:value,key:value,key:value,...}
df = pd.DataFrame(list(my_dict.items()),columns = ['column1','column2'])
print("Before Sorting"/n)
print df.to_string(index=False)
df.sort_values(by=['col2']
print("After Sorting"/n)
print df.to_string(index=False)'https://stackoverflow.com/questions/73396262
复制相似问题