[英]Read list items as string in dataframe pandas
I have such lines in the code that reads values from excel file我在从 excel 文件中读取值的代码中有这样的行
df = pd.read_excel('Data.xlsx', sheet_name='Sheet1')
mylist = df['Numbers'].tolist()
I got a list of numbers like that [1, 2, 3, 4, 5, 100]
How to convert the numbers in that list to string?我有一个类似
[1, 2, 3, 4, 5, 100]
的数字列表如何将该列表中的数字转换为字符串?
I am assuming that the problem you're having is probably because join
connects elements inside a list of strings
and not integers
(which is what you have in that list).我假设您遇到的问题可能是因为
join
连接strings
列表中的元素而不是integers
(这就是您在该列表中的内容)。 Therefore you can:因此,您可以:
a = ''.join(map(str, my_list)) #1st way
b = ''.join(str(i) for i in my_list) #2nd way
print(a), print(b)
12345100
12345100
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.