имеют эти текстовые файлы со значениями
google.com('172.217.163.46', 443)
commonName: *.google.com
issuer: GTS CA 1O1
notBefore: 2020-02-12 11:47:11
notAfter: 2020-05-06 11:47:11
facebook.com('31.13.79.35', 443)
commonName: *.facebook.com
issuer: DigiCert SHA2 High Assurance Server CA
notBefore: 2020-01-16 00:00:00
notAfter: 2020-04-15 12:00:00
Как преобразовать это в df
попробовал это и получил частично успешно:
f = open("out.txt", "r")
a=(f.read())
a=(pd.read_csv(StringIO(data),
header=None,
#use a delimiter not present in the text file
#forces pandas to read data into one column
sep="/",
names=['string'])
#limit number of splits to 1
.string.str.split(':',n=1,expand=True)
.rename({0:'Name',1:'temp'},axis=1)
.assign(temp = lambda x: np.where(x.Name.str.strip()
#look for string that ends
#with a bracket
.str.match(r'(.*[)]$)'),
x.Name,
x.temp),
Name = lambda x: x.Name.str.replace(r'(.*[)]$)','Name')
)
#remove whitespace
.assign(Name = lambda x: x.Name.str.strip())
.pivot(columns='Name',values='temp')
.ffill()
.dropna(how='any')
.reset_index(drop=True)
.rename_axis(None,axis=1)
.filter(['Name','commonName','issuer','notBefore','notAfter'])
)
Но это цикл и предоставление мне нескольких данных, таких как отдельные строки, имеет несколько дубликатов