Python Forum
How to filter out Column data From Multiple rows data?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to filter out Column data From Multiple rows data?
#5
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 :-

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('--')

wdf
The walmart json file.txt line of text, will need changing to what it is for you.

Best Regards

Eddie Winch Smile
Reply


Messages In This Thread
RE: How to filter out Column data From Multiple rows data? - by eddywinch82 - Feb-01-2021, 10:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 507 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Filter data into new dataframe as main dataframe is being populated cubangt 8 1,099 Oct-23-2023, 12:43 AM
Last Post: cubangt
  Returning Column and Row Data From Spreadsheet knight2000 0 486 Oct-22-2023, 07:07 AM
Last Post: knight2000
  how do you style data frame that has empty rows. gsaray101 0 554 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  Database that can compress a column, or all data, automatically? Calab 3 1,265 May-22-2023, 03:25 AM
Last Post: Calab
  Code for pullng all data in a column EmBeck87 5 1,190 Apr-03-2023, 03:43 PM
Last Post: deanhystad
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,285 Dec-19-2022, 11:11 PM
Last Post: Stockers
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,988 Dec-12-2022, 08:22 PM
Last Post: jh67
  Write sql data or CSV Data into parquet file mg24 2 2,517 Sep-26-2022, 08:21 AM
Last Post: ibreeden
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 882 Sep-08-2022, 06:32 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020