如果数据框中的列类型为int
,float
或string
,我们可以使用columnName.unique()
获取其唯一值。
但是,如果此列是列表,例如, [1,2,3]。
我怎样才能获得此专栏的unique
?
答案 0 :(得分:0)
我认为您可以将值转换为元组,然后unique
效果很好:
df = pd.DataFrame({'col':[[1,1,2],[2,1,3,3],[1,1,2],[1,1,2]]})
print (df)
col
0 [1, 1, 2]
1 [2, 1, 3, 3]
2 [1, 1, 2]
3 [1, 1, 2]
print (df['col'].apply(tuple).unique())
[(1, 1, 2) (2, 1, 3, 3)]
L = [list(x) for x in df['col'].apply(tuple).unique()]
print (L)
[[1, 1, 2], [2, 1, 3, 3]]
答案 1 :(得分:0)
您无法在不可清除的类型(例如列表)上应用<EAI>
<SvcRS>
<accountHeader>
<errorHost>orgA</errorHost>
</accountHeader>
<accoutnDetails>
<accountNumber>0000000111118800</accountNumber>
<accountType>credit</accountType>
<errorDetails>
<code>111</code>
<description>Account is not valid</description>
</errorDetails>
</accoutnDetails>
</SvcRS>
<SvcRS>
<accountHeader>
<errorHost>orgB</errorHost>
</accountHeader>
<accoutnDetails>
<accountNumber>000111118800</accountNumber>
<accountType>credit</accountType>
<errorDetails>
<code>0001</code>
<description>Not enough balance</description>
</errorDetails>
</accoutnDetails>
</SvcRS>
</EAI>
。您需要转换为可清除类型才能执行此操作。
使用最新版本的pandas的更好解决方案是使用 android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
flavorDimensions "default"
productFlavors {
dev {
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
task jarTask(type: Jar) {
baseName="my-library"
from 'src/main/java'
}
task createJarWithDependencies(type: Jar) {
baseName = "my-library"
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
configurations {
jarConfiguration
}
artifacts {
jarConfiguration jarTask
}
//this are library that i want to include in jar
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/converter-gson-2.3.0.jar')
implementation files('libs/converter-simplexml-2.3.0.jar')
implementation files('libs/ksoap2-android-assembly-3.4.0-jar-with-dependencies.jar')
implementation files('libs/logging-interceptor-3.9.1.jar')
implementation files('libs/okhttp-3.9.1.jar')
implementation files('libs/okio-1.13.0.jar')
implementation files('libs/retrofit-2.3.0.jar')
implementation files('libs/simple-xml-2.7.1.jar')
}
并避免迭代值以再次转换为列表。
unique()
这将返回列出唯一值。