简体   繁体   中英

how to pass in f-string inside another string in dataframe series

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM