函数的作用是:改变列表中元素的顺序

2024-05-16 14:59:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧“csv”如下

movieId |               title|              genres|
+-------+--------------------+--------------------+
|      1|    Toy Story (1995)|Adventure|Animati...|
|      2|      Jumanji (1995)|Adventure|Childre...|

命令1:print("PRINT",csvData.dtypes)
输出1:('PRINT', [('movieId', 'int'), ('title', 'string'), ('genres', 'string')])

命令2:print ("SAMPLE dictionary**",dict(csvData.dtypes))

输出2:'SAMPLE dictionary**', {'genres': 'string', 'movieId': 'int', 'title': 'string'}

在比较两个输出之后,我们可以看到dict()函数改变了元素的顺序,如何避免这种情况?你知道吗


Tags: 数据sample命令stringdictionarytitledictint