Home > Mobile >  how to pass in f-string inside another string in dataframe series
how to pass in f-string inside another string in dataframe series

Time:02-17

How does one pass the number 6 defined as a string into 'text2=self.nmb' where self.nmb is a method attribute

self.nmb='6'
X = pd.DataFrame({'A':['text1', 'text2=f'{self.nmb}'']})
print(X)

Desired output

           A
0      text1
1    text2=6

CodePudding user response:

Use:

In [1232]: nmb='6'

In [1235]: X = pd.DataFrame({'A':['text1', f'text2={nmb}']})

In [1236]: X
Out[1236]: 
         A
0    text1
1  text2=6
  • Related