Wenn ich Ihre Frage richtig verstehe, glaube ich, dass es die NaN-Werte in allen Spalten füllen wird.
Von [http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reindex.html][1]
import pandas as pd
index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror']
new_index= ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10','Chrome']
df = pd.DataFrame({
'http_status': [200,200,404,404,301],
'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
index=index)
df
Returns:
http_status response_time
Firefox 200 0.04
Chrome 200 0.02
Safari 404 0.07
IE10 404 0.08
Konqueror 301 1.00
Während df.reindex(new_index, fill_value='missing')
Rückkehr:
http_status response_time
Safari 404 0.07
Iceweasel missing missing
Comodo Dragon missing missing
IE10 404 0.08
Chrome 200 0.02
Keine dieser Säulen sind neu, aber die nan Werte in noch gefüllt werden. Ich würde auf jeden Fall meine Erklärung testen, bevor ich in die Produktion gehe tion. Ich bin mir nicht sicher, ob ich den richtigen Kontext habe.
Edit:
Ich sollte hinzufügen, dass es scheint, als ob, wenn die Werte vor 'NaN' waren, wird die .reindex nicht, diese Werte füllen:
import pandas as pd
index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror']
new_index= ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10','Chrome']
df = pd.DataFrame({
'http_status': [200,'NaN',404,404,301],
'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
index=index)
df
Returns:
http_status response_time
Safari 404 0.07
Iceweasel NaN NaN
Comodo Dragon NaN NaN
IE10 404 0.08
Chrome NaN 0.02
Während df.reindex (neuer_Index, fill_value = 'fehlend') zurückkommt:
http_status response_time
Safari 404 0.07
Iceweasel missing missing
Comodo Dragon missing missing
IE10 404 0.08
Chrome NaN 0.02
Der HTTP-Status-Chrome-Wert wurde durch das Wechseln des Index nicht beeinflusst.
Danke für die Antwort @cptnhaddock. Das ist sehr hilfreich! –