Ich habe zwei pandas
DataFrames
. Sie haben die gleichen Spalten, und so möchte ich die Daten von jedem nehmen und es in eine größere DataFrame
setzen. Das Problem ist, dass die Nummer, die jede Zeile identifiziert, wörtlich kopiert wird, während ich möchte, dass sie intelligent aktualisiert wird.Verketten Sie zwei Pandas DataFrames, ohne Zeilen-IDs zu duplizieren?
Hier ist, was ich habe:
import pandas as pd
df_one = pd.DataFrame([
{'animal': 'cat', 'color': 'black'},
{'animal': 'dog', 'color': 'brown'}])
df_two = pd.DataFrame([
{'animal': 'fish', 'color': 'red'},
{'animal': 'bird', 'color': 'blue'}])
print(pd.DataFrame([df_one, df_two]))
Welche Ausgänge:
animal color
0 cat black
1 dog brown
0 fish red
1 bird blue
Der Ausgang ich will, ist:
animal color
0 cat black
1 dog brown
2 fish red
3 bird blue