简体   繁体   中英

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)

Ok guys.I solved the problem.The mistake was the square brackets.In df.reindex part,I used 2 square brackets.But I should have use one.So thank you so much for your helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM