Skip to content

Instantly share code, notes, and snippets.

@flutefreak7
Created October 30, 2020 19:23
Show Gist options
  • Save flutefreak7/b4eb6a93565c375d79b791c2bbd672b1 to your computer and use it in GitHub Desktop.
Save flutefreak7/b4eb6a93565c375d79b791c2bbd672b1 to your computer and use it in GitHub Desktop.
Comparing pandas update vs dict update
import pandas as pd
data1 = pd.DataFrame({'A': [1, 2, 3, 4]}, index=[0, 1, 2, 3])
data2 = pd.DataFrame({'A': [10, 11, 12, 13]}, index=[2, 3, 4, 5])
data3 = data1.copy()
data3.update(data2)
print(data3)
data1 = pd.DataFrame({'A': [1, 2, 3, 4]}, index=[0, 1, 2, 3])
data2 = pd.DataFrame({'A': [10, 11, 12, 13]}, index=[2, 3, 4, 5])
d1 = {0: 1, 1: 2, 2: 3, 3: 4}
d2 = {2: 10, 3: 11, 4: 12, 5: 13}
d3 = d1.copy()
d3.update(d2)
print(d3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment