简体   繁体   English

将列表中的多个 Int64Index([], dtype='int64') 转换为列表

[英]Convert multiple Int64Index([], dtype='int64') in a list to a list

I have a list with int64index, I want to change it to a flat list.我有一个带有 int64index 的列表,我想将其更改为平面列表。 Can you help me with this?你能帮我解决这个问题吗? here is a simple example.这是一个简单的例子。

l = [Int64Index([518], dtype='int64'), Int64Index([599], dtype='int64'), Int64Index([614], dtype='int64')]

The output: output:

[518, 599, 614]

You should probably fix whatever process produced this in the first place, but you can get a list of python int objects using something like:您可能应该首先修复产生此问题的任何过程,但您可以使用以下内容获取 python int对象的list

[x for idx in l for x in idx.tolist()]

You can use np.ravel and tolist() to get the flattened python list.您可以使用np.raveltolist()来获取扁平的 python 列表。

np.ravel(l).tolist()

If you want pandas Index:如果你想要 pandas 索引:

pd.Index(np.ravel(l))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 熊猫:将列表转换为int64index - pandas: convert list to int64index 将Int64Index更改为Index,将dtype = int64更改为dtype = object - Change Int64Index to Index and dtype=int64 to dtype=object TypeError:无法使用 Int64Index 类型的这些索引器 [Int64Index([5], dtype='int64')] 对 Int64Index 进行位置索引 - TypeError: cannot do positional indexing on Int64Index with these indexers [Int64Index([5], dtype='int64')] of type Int64Index [Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64', name='index')] 中没有一个在 [index] - None of [Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64', name='index')] are in the [index] KeyError: "[Int64Index([ 12313,\\n, 34534],\\n dtype='int64', leng - KeyError: "None of [Int64Index([ 12313,\n , 34534],\n dtype='int64', leng 读取 CSV & Columns - KeyError: “[Int64Index([0, 1, 2, 3], dtype='int64')] 都在 [columns] 中” - Reading CSV & Columns - KeyError: “None of [Int64Index([0, 1, 2, 3], dtype='int64')] are in the [columns]” 关键错误:[Int64Index([…]dtype='int64')] 均不在 [columns] 中 - Key Error: None of [Int64Index([…]dtype='int64')] are in the [columns] KeyError:“[Int64Index dtype='int64', length=9313)] 都不在 [columns]” - KeyError: "None of [Int64Index dtype='int64', length=9313)] are in the [columns]" 关键错误:[Int64Index…] dtype='int64] 均不在 [columns] 中 - Key Error: None of [Int64Index…] dtype='int64] are in the [columns] Receiving KeyError: “[Int64Index([ ... dtype='int64', length=1323)] 都不在 [columns]” - Receiving KeyError: "None of [Int64Index([ ... dtype='int64', length=1323)] are in the [columns]"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM