Python Forum
String to List question help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String to List question help
#5
No problem. Same solution with a string. Why did you mention touchstone files in the OP?
import pandas as pd
from io import StringIO  # Might need to use TextIO for input from GPIB.

gpib_string = """# 34589043! FILE NAME
! DATE NOW
! RAW DATA
# More information
!   FREQ	S11M	S21M	S21A
0.11444405920970335	0.22851792934978143	0.16724464908750036	0.054813079444560264
0.11565032195951042	0.23010933442970138	0.3048773751796404	0.11465260170716174
0.20102541854079847	0.27830101316888567	0.3995954975408248	0.12034618280172404
0.41276142607996513	0.31147127777115224	0.46636510024384636	0.2806783250819618
0.495356229079312	0.3495931528852747	0.6389401268977468	0.38079631999232333
0.556074773658631	0.3894689120388013	0.6779475794713076	0.43728550829612134
0.6332585933784733	0.4924761223011904	0.7503465368809027	0.7386632480838207
0.6341059239183447	0.5130383410762516	0.8554371206142789	0.7695854491274398
0.8902822004610119	0.7219019187548961	0.8712110079483135	0.8443884202719537
0.9170577193238573	0.7970927214052331	0.9344766589022325	0.8597198838156557"""

# Read column names from 4th line in string.  Remove leading "!"
columns = gpib_string.split("\n")[4][1:].split()
 
# Read file into dataframe.  Skip the first 5 rows and use the column
# names from above.

df = pd.read_csv(StringIO(gpib_string), sep="\t", skiprows=5, names=columns)
print(df)
Reply


Messages In This Thread
String to List question help - by James_Thomas - Sep-05-2023, 03:52 PM
RE: String to List question help - by deanhystad - Sep-05-2023, 06:45 PM
RE: String to List question help - by James_Thomas - Sep-06-2023, 09:14 AM
RE: String to List question help - by Pedroski55 - Sep-06-2023, 10:59 AM
RE: String to List question help - by deanhystad - Sep-06-2023, 12:22 PM
RE: String to List question help - by James_Thomas - Sep-06-2023, 01:17 PM
RE: String to List question help - by deanhystad - Sep-06-2023, 02:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  syntax error question - string mgallotti 5 1,496 Feb-03-2023, 05:10 PM
Last Post: mgallotti
Big Grin General programming question (input string)[ jamie_01 2 1,711 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,625 May-24-2021, 08:48 AM
Last Post: bowlofred
  Question on HTML formatting with set string in message Cknutson575 3 3,631 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  question: finding multiple strings within string djf123 4 3,096 May-16-2020, 01:00 PM
Last Post: snippsat
  Simple newb string question Involute 2 2,330 Sep-08-2019, 12:50 AM
Last Post: Involute
  string parsing question ( I think) diggee17 4 3,145 Jul-24-2019, 02:37 PM
Last Post: diggee17
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 3,367 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  please help with this question about using operators to multiply a string? GilesTwigg 3 4,525 Feb-27-2019, 04:13 PM
Last Post: ichabod801
  about List question longmail 2 2,476 Nov-30-2018, 02:08 AM
Last Post: longmail

Forum Jump:

User Panel Messages

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