Feb-01-2021, 10:39 PM
(This post was last modified: Feb-01-2021, 10:39 PM by eddywinch82.)
Hi firaki12345,
I have achieved what you wanted doing, using str.extract a regular expression, and a couple of other changes.
Here is the finished Code, let me know if you would like any other changes doing :-
Best Regards
Eddie Winch
I have achieved what you wanted doing, using str.extract a regular expression, and a couple of other changes.
Here is the finished Code, let me know if you would like any other changes doing :-
import json import pandas as pd import re with open("walmart json file.txt") as f: data = json.load(f) walmart = data["items"] wdf = pd.DataFrame(walmart,columns=["productId","primaryOffer"]) print(wdf.loc[0,"primaryOffer"]) pd.set_option('display.max_colwidth', None) wdf['primaryOffer'] = wdf['primaryOffer'].astype(str) wdf['primaryOffer'] = wdf.primaryOffer.str.replace("'", '') wdf['primaryOffer'] = wdf.primaryOffer.str.replace(",", '') wdf['minPrice'] = wdf.primaryOffer.str.extract('.*minPrice:\s?(\d+[.]?\d*)', expand = False) wdf['maxPrice'] = wdf.primaryOffer.str.extract('.*maxPrice:\s?(\d+[.]?\d*)', expand = False) wdf['offerPrice'] = wdf.primaryOffer.str.extract('.*offerPrice:\s?(\d+[.]?\d*)', expand = False) wdf=wdf.fillna('--') wdfThe walmart json file.txt line of text, will need changing to what it is for you.
Best Regards
Eddie Winch
