将列表中的值分解为元组

时间:2018-05-26 14:49:13

标签: python list tuples

我从数据框功能创建了一个列表/系列。这是一长串的价值清单:

print(a)

AABA     0.001028
AAL      0.000975
AAME    -0.000056
AAPL    -0.000749
AAWW     0.000311
....

我想将这长长的内容列表分成[AABA, 0.001028],[AAL, 0.000975]等元组。我尝试了split()函数但得到了没有split属性的列表错误。

我也试过这个:

list=a
list = list[0].split(" ")

错误消息为'Series' object has no attribute 'split'

怎么办?

3 个答案:

答案 0 :(得分:0)

使用.tolist() refer doc

将系列对象转换为列表
v = df['col1'].tolist()

[i.split(" ") for i in v]

答案 1 :(得分:0)

这样做:

AABA = 0.001028
AAL = 0.000975
AAME = -0.000056
AAPL = -0.000749
AAWW = 0.000311

myList = [AABA, AAL, AAME, AAPL, AAWW]
print(myList)

答案 2 :(得分:0)

如果它实际上是一个Pandas系列,其中org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:mapreduce_shuffle does not exist at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl.instantiateExceptionImpl(SerializedExceptionPBImpl.java:171) at org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl.instantiateException(SerializedExceptionPBImpl.java:182) at org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl.deSerialize(SerializedExceptionPBImpl.java:106) at org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherImpl$Container.launch(ContainerLauncherImpl.java:162) at org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherImpl$EventProcessor.run(ContainerLauncherImpl.java:408) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) ...是索引,将系列转换为dict,然后获取dict中的项目:

AABA