Last active
April 21, 2020 09:34
-
-
Save lukasjoc/58e576536efe351a1085a6a954a9f4dc to your computer and use it in GitHub Desktop.
get deltas from other frame and keep incoming frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
db_data = [ | |
{"id": 1, "name": "Luads", "number": "000000000000", "number_active": 1}, | |
{"id": 2, "name": "Luads", "number": "000000000000", "number_active": 1}, | |
{"id": 3, "name": "Luads", "number": "000000000000", "number_active": 1}, | |
{"id": 4, "name": "Lukas", "number": "000000000000", "number_active": 1}, | |
{"id": 5, "name": "Luisd", "number": "000000000000", "number_active": 1}, | |
{"id": 6, "name": "Jocham", "number":"000000000000", "number_active": 1}, | |
] | |
input_data = [ | |
{"id": 1, "name": "L", "number": "0000", "number_active": 1}, | |
{"id": 2, "name": "Lukas", "number": "23", "number_active": 1}, | |
] | |
df_db = pd.json_normalize(db_data) | |
df_input = pd.json_normalize(input_data) | |
print(df_db) | |
print(df_input) | |
# this is not the best solution. but i need to figure out a way to use loc and decide between views and replications | |
common = df_db.merge(df_input, on=["id"]) | |
dropped_things = df_db[(~df_db.id.isin(common.id))] | |
dropped_things["number_active"] = 0 | |
want = pd.concat([df_input, dropped_things]) | |
print(want) | |
db_data = [ | |
{"id": 1, "name": "Luads", "number": "000000000000", "number_active": 1}, | |
{"id": 2, "name": "Luads", "number": "000000000000", "number_active": 0}, | |
{"id": 3, "name": "Luads", "number": "000000000000", "number_active": 1}, | |
] | |
input_data = [ | |
{"id": 1, "name": "L", "number": "0000", "number_active": 1}, | |
{"id": 3, "name": "L", "number": "0000", "number_active": 1}, | |
{"id": 4, "name": "Lukas", "number": "23", "number_active": 1}, | |
{"id": 5, "name": "Lukas", "number": "23", "number_active": 1}, | |
] | |
# this is not the best solution. but i need to figure out a way to use loc and decide between views and replications | |
common = df_db.merge(df_input, on=["id"]) | |
dropped_things = df_db[(~df_db.id.isin(common.id))] | |
dropped_things["number_active"] = 0 | |
want = pd.concat([df_input, dropped_things]) | |
print(want) | |
df_db = pd.json_normalize(db_data) | |
df_input = pd.json_normalize(input_data) | |
print(df_db) | |
print(df_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i dont really know how to resolve this warning. so if you know comment below