0

I have the list below and I would like to remove the brackets around the numbers They are set as strings. When I try to use the code below everything after the comma is deleted and when I try to use the second code, everything but the brackets are deleted. Does anybody know why this is happening and how to fix it?

   1. df['id'].str.get(0)

   2. df['id'].str[10:]

Example of the list I`m using

0      [755316924681835123, 624417788919829344]
3      [755316924681835123, 624417788919829344]
4      [767214484270895116, 784006322814210766]
  • Re u looking for something like `df['id'].apply(lambda x: str(x)[1:-1])` ? – Epsi95 Feb 17 '21 at 16:46
  • Yes, thank you. I tried this as well but without lambda x:.Could you please explain what is the difference between using lambda and not using it? – Mariana Rodrigues Feb 17 '21 at 16:48
  • I am not sure whether `df['id']` is `str` or not. That is why I converted it into string. If it is already in `string` no need to use lambda. – Epsi95 Feb 17 '21 at 16:50
  • I see, however when I run df.info the id show as an object, shouldn't have worked without lambda? – Mariana Rodrigues Feb 17 '21 at 16:51
  • check https://stackoverflow.com/questions/21018654/strings-in-a-dataframe-but-dtype-is-object – Epsi95 Feb 17 '21 at 16:56
  • If it is already string it will work without lambda. but if it is `list` then the notation will not work – Epsi95 Feb 17 '21 at 16:59

1 Answers1

0
list = [17382639173, 183929838361]

list_string = f'{list[0]} {list[1]}'
print(list)

This should work to put them into one string without brackets. And if u want the comma between them u can write it like so.

list = [17382639173, 183929838361]

list_string = f'{list[0]},  {list[1]}'
print(list)