Created
August 2, 2023 21:10
-
-
Save gregjlee/84b30443f1e4385262ce18b882d636f8 to your computer and use it in GitHub Desktop.
Script to update a subscriptions csv with a new feature
This file contains hidden or 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 | |
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