Skip to content

Instantly share code, notes, and snippets.

@gregjlee
Created August 2, 2023 21:10
Show Gist options
  • Save gregjlee/84b30443f1e4385262ce18b882d636f8 to your computer and use it in GitHub Desktop.
Save gregjlee/84b30443f1e4385262ce18b882d636f8 to your computer and use it in GitHub Desktop.
Script to update a subscriptions csv with a new feature
import pandas as pd
import json
# reading the csv file
df = pd.read_csv("c.csv")
df.fillna('{}', inplace=True)
for i, r in df.iterrows():
json_object = json.loads(str(r['meta_data']))
feature = 'new_feature_to_add'
if "features" in json_object:
json_object['features'] += [feature]
else:
json_object['features'] = [feature]
df.at[i,'meta_data'] = json.dumps(json_object)
df.columns = ['subscription[id]', 'subscription[meta_data]']
# writing into the file
df.to_csv("update-0802.csv", index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment