熊猫整数列删除最后三位数字

时间:2018-12-23 03:38:46

标签: pandas

以pandas df为例,该列的所有整数均为整数,而有些则为NAN。

raw capitalSurplus 188883000 totalLiab 2589242000 totalStockholderEquity 6740732000 minorityInterest 27549000 otherCurrentLiab 40412000 totalAssets 9357523000 endDate 1483142400 commonStock 5818867000 retainedEarnings 732982000 otherLiab 746117000 otherAssets 6034000 totalCurrentLiabilities 436539000 propertyPlantEquipment 9135741000 totalCurrentAssets 212758000 longTermInvestments 2990000 netTangibleAssets 6740732000 netReceivables 201288000 longTermDebt 1406586000 accountsPayable 396127000 otherCurrentAssets NAN

ps。 df已转置。

期望结果是,尽管有NAN列,但所有列的最后三位数字('000')被删除

并保持endDate不变:

endDate     1483142400

1 个答案:

答案 0 :(得分:0)

如果12:12:38 PM: Executing tasks 'clean install'... Executing tasks: [clean, install] :package-name:clean :package-name:preBuild UP-TO-DATE :package-name:preReleaseBuild UP-TO-DATE :package-name:compileReleaseAidl NO-SOURCE :package-name:compileReleaseRenderscript :package-name:checkReleaseManifest :package-name:generateReleaseBuildConfig :package-name:generateReleaseResValues :package-name:generateReleaseResources :package-name:packageReleaseResources :package-name:processReleaseManifest :package-name:generateReleaseRFile :package-name:prepareLintJar UP-TO-DATE :package-name:generateReleaseSources :package-name:javaPreCompileRelease :package-name:compileReleaseJavaWithJavac :package-name:extractReleaseAnnotations :package-name:mergeReleaseConsumerProguardFiles UP-TO-DATE :package-name:mergeReleaseShaders :package-name:compileReleaseShaders :package-name:generateReleaseAssets :package-name:packageReleaseAssets :package-name:packageReleaseRenderscript NO-SOURCE :package-name:processReleaseJavaRes NO-SOURCE :package-name:transformResourcesWithMergeJavaResForRelease :package-name:transformClassesAndResourcesWithSyncLibJarsForRelease :package-name:compileReleaseNdk NO-SOURCE :package-name:mergeReleaseJniLibFolders :package-name:transformNativeLibsWithMergeJniLibsForRelease :package-name:transformNativeLibsWithSyncJniLibsForRelease :package-name:bundleReleaseAar ...src/main/java/.../DjangoErrorListener.java:19: error: package com.android.volley does not exist import com.android.volley.AuthFailureError; ^ ...src/main/java/.../DjangoErrorListener.java:20: error: package com.android.volley does not exist import com.android.volley.ClientError; ^ ...src/main/java/.../DjangoErrorListener.java:21: error: package com.android.volley does not exist import com.android.volley.NetworkError; ^ … MANY SIMILAR ERRORS … ^ ...src/main/java/.../DjangoErrorListener.java:32: error: package Response does not exist public abstract class DjangoErrorListener implements Response.ErrorListener { ^ ...src/main/java/.../DjangoErrorListener.java:64: error: cannot find symbol public void onErrorResponse(VolleyError error) { ^ symbol: class VolleyError location: class DjangoErrorListener ...src/main/java/.../DjangoBaseRequest.java:20: error: package android.support.annotation does not exist import android.support.annotation.Nullable; ^ symbol: class JsonRequest ...src/main/java/.../DjangoBaseRequest.java:68: error: package Response does not exist Response.Listener<T> listener, ^ ...src/main/java/.../DjangoBaseRequest.java:76: error: cannot find symbol abstract protected Response<T> parseNetworkResponse(NetworkResponse response); ^ symbol: class NetworkResponse location: class DjangoBaseRequest<T> where T is a type-variable: T extends Object declared in class DjangoBaseRequest ...src/main/java/.../DjangoBaseRequest.java:76: error: cannot find symbol abstract protected Response<T> parseNetworkResponse(NetworkResponse response); ^ symbol: class Response location: class DjangoBaseRequest<T> where T is a type-variable: T extends Object declared in class DjangoBaseRequest ...src/main/java/.../DjangoJSONArrayResponseRequest.java:21: error: package android.support.annotation does not exist import android.support.annotation.Nullable; ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:23: error: package com.android.volley does not exist import com.android.volley.NetworkResponse; ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:27: error: package com.android.volley.toolbox does not exist import com.android.volley.toolbox.JsonRequest; ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:61: error: package Response does not exist Response.Listener<JSONArray> listener, ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:85: error: package Response does not exist Response.Listener<JSONArray> listener, ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:104: error: cannot find symbol protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { ^ symbol: class NetworkResponse location: class DjangoJSONArrayResponseRequest ...src/main/java/.../DjangoJSONArrayResponseRequest.java:104: error: cannot find symbol protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { ^ ...src/main/java/.../DjangoJSONObjectRequest.java:23: error: package com.android.volley does not exist import com.android.volley.NetworkResponse; ^ ...src/main/java/.../DjangoJSONObjectRequest.java:62: error: package Response does not exist Response.Listener<JSONObject> listener, ^ … MANY SIMILAR ERRORS … ...src/main/java/.../DjangoJSONObjectRequest.java:84: error: package Response does not exist Response.Listener<JSONObject> listener, ^ ...src/main/java/.../DjangoJSONObjectRequest.java:103: error: cannot find symbol protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { ^ symbol: class NetworkResponse location: class DjangoJSONObjectRequest ...src/main/java/.../DjangoJSONObjectRequest.java:103: error: cannot find symbol protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { ^ symbol: class Response location: class DjangoJSONObjectRequest ...src/main/java/.../DjangoBaseRequest.java:67: error: cannot find symbol @Nullable String jsonRequest, ^ … MANY SIMILAR ERRORS … symbol: class Nullable location: class DjangoJSONObjectRequest ...src/main/java/.../DjangoJSONObjectRequest.java:85: error: cannot find symbol @Nullable DjangoErrorListener errorListener, ^ symbol: class Nullable location: class DjangoJSONObjectRequest ...src/main/java/.../DjangoBaseRequest.java:81: error: malformed HTML * @return Map<String, String> a Map of headers ^ ...src/main/java/.../DjangoBaseRequest.java:81: error: bad use of '>' * @return Map<String, String> a Map of headers ^ ...src/main/java/.../DjangoBaseRequest.java:82: error: reference not found * @throws AuthFailureError from super ^ ...src/main/java/.../DjangoBaseRequest.java:65: warning: no @param for context public DjangoBaseRequest(int method, ^ javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. ...src/main/java/.../DjangoErrorListener.java:62: error: reference not found * @param error A {@link VolleyError} object. ^ ...src/main/java/.../DjangoJSONArrayResponseRequest.java:46: error: reference not found * Based on {@link com.android.volley.toolbox.JsonObjectRequest} ^ javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. ...src/main/java/.../DjangoJSONObjectRequest.java:47: error: reference not found * Based on {@link com.android.volley.toolbox.JsonObjectRequest} ^ javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. javadoc: warning - Class Nullable not found. :package-name:javadoc 6 errors 62 warnings :package-name:javadoc FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':package-name:javadoc'. > Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '...build/tmp/javadoc/javadoc.options' * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 1s 23 actionable tasks: 21 executed, 2 up-to-date 12:12:40 PM: Tasks execution finished 'clean install'. 不是NAN,则可以使用np.nan替换它们。

其中,我通过使用df.replace

将列重命名为A,B

然后,您可以使用内置功能floordiv()进行以下操作:

df.columns = ['A','B']

这将删除endDate行以外的最后3个零,并更新相应索引中的B列。

或者,您也可以使用df.B.update(df[df.A!='endDate']['B'].floordiv(1000)) 删除最后3个零,如下所示:

//