Python Forum
Extracting variable values from labels on csv file using Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting variable values from labels on csv file using Python
#1
Hello everyone.

I have a CSV file with one thousand row and each row its structure is like that (Show 2 lines):

Output:
Line 219 (6420),Dh," ""url"": ""https://r3---sn-gxqpgpn-h5ql.googlevideo.com/videoplayback?ipbits=0&requiressl=yes&gir=yes&pcm2cms=yes&ip=150.214.57.8&fvip=5&c=WEB&id=o-AKPE5P1-L_x8zzDRYj5aoX3bYJ1W02pyCMpEI4-dsRC-&gcr=es&mm=31%2C29&mn=sn-gxqpgpn-h5ql%2Csn-h5q7dnlk&signature=201841BEA18EE01EE5C51CEE1487A4CAC75DED51.0B35DB9CB1ADB52AFFF24A3250F9B1C5708068ED&keepalive=yes&sparams=clen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Crequiressl%2Csource%2Cexpire&mt=1541693372&mv=m&initcwndbps=642500&ms=au%2Crdu&itag=251&mime=audio%2Fwebm&pl=16&expire=1541715093&clen=1853458&ei=NWDkW6LwLJic1waombfoBQ&key=yt6&source=youtube&dur=117.241&txp=5511222&lmt=1538050727946448&alr=yes&cpn=mH58o0Uz_dI7ZuKp&cver=2.20181106&range=309760-378453&rn=27&rbuf=5457""," Line 479 (106021),Dh," ""url"": ""https://r3---sn-gxqpgpn-h5ql.googlevideo.com/videoplayback?ipbits=0&requiressl=yes&gir=yes&pcm2cms=yes&ip=150.214.57.8&fvip=5&xtags=vproj%3Dmesh&c=WEB&id=o-AKPE5P1-L_x8zzDRYj5aoX3bYJ1W02pyCMpEI4-dsRC-&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C264%2C266%2C271%2C278%2C298%2C299%2C302%2C303%2C304%2C305%2C308%2C313%2C315&mm=31%2C29&mn=sn-gxqpgpn-h5ql%2Csn-h5q7dnlk&signature=369A4451CD5098765653E430D3FBFF20D4F8EF36.349B11C21BE7DEDFA4CA70F8365808EB9153FE4C&keepalive=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Crequiressl%2Csource%2Cxtags%2Cexpire&mt=1541693372&mv=m&initcwndbps=642500&ms=au%2Crdu&itag=315&mime=video%2Fwebm&pl=16&gcr=es&expire=1541715093&clen=347859091&ei=NWDkW6LwLJic1waombfoBQ&key=yt6&source=youtube&dur=117.183&lmt=1492587801555590&alr=yes&cpn=mH58o0Uz_dI7ZuKp&cver=2.20181106&range=32056563-38295938&rn=28&rbuf=5553"","
I am new working with python and csv files as input. I just wanna extract from each line 9 labels value and save them, sorted by columns in an excel file, for example:


Output:
Line url ip lmt mime itag dur clen rbuf 219 https://r3---sn-gxqpgpn-h5ql.googlevideo.com 150.214.57.8 1538050727946440 audio 251 117.241 1853458 5457 479 https://r3---sn-gxqpgpn-h5ql.googlevideo.com 150.214.57.9 1492587801555590 video 315 117.183 347859091 5553
i appreciate very much your help.
Reply
#2
You'll want to read them in, probably using the csv module. Then you'll need to trim out the labels. If they are a consistent length, like the url one appears to be, you could just trim it out with string slicing.

We don't generally write code for people around here, we help them fix their code. So at this point it would be up to you to try out those suggestions and then come back to us if you have problems.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting link list to json file naor 5 2,601 Sep-17-2020, 04:16 PM
Last Post: micseydel
  How to make a variable contain multiple values stevenjwilliams83 10 3,531 Apr-30-2020, 07:22 AM
Last Post: pyzyx3qwerty
  help with extracting and matching values in a text file hoeleeschitt 4 52,712 May-03-2018, 05:47 AM
Last Post: hoeleeschitt
  file a table of values Ybivashka322 4 3,699 Dec-14-2017, 06:11 PM
Last Post: mpd

Forum Jump:

User Panel Messages

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