簡體   English   中英

python pandas 重新索引將所有數據轉換為 NaN

[英]python pandas reindexing converts all data to NaN

import pandas as pd

import numpy as np

data = np.random.randint(10,100,15).reshape(5,3)


df = pd.DataFrame(data,index = ["a","c","e","f","h"],columns = ["column1","column2","column3"])

df = df.reindex([["a","b","c","d","e","f","g","h"]])

result = df

result = df.drop("column1",axis = 1)

print(result)

好的,伙計們。我解決了問題。錯誤是方括號。在 df.reindex 部分,我使用了 2 個方括號。但我應該使用一個。非常感謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM