How to convert each list item into string in a column of data frame. ?

0 votes

Actually, I have used split on a column in the data frame, not split have returned a list and now I cannot use any function on that data frame column. Its throwing error:" list hashable type"

need help either to convert each list element to string or need any function which can split the string on the :(colon) I want everything before the colon and want to discard everything after that. eg, "ABC:ashjgfja" so I want ABC and discard the rest of the string.

Any help is much appreciated

Thanks

Feb 5 in Python by Parul
• 130 points

edited Feb 5 by Gitika 117 views

1 answer to this question.

0 votes

Hey,

To split a string you can use split method, which splits a string into a list. You can specify the separator as show below in the syntax:

For eg,

txt= "ABC:ashjgfja"

x=txt.split(":")

print(x)

This will print your string ABC but will discard the string after the separator you have provided.

Try this, if it helps then let me know and if you face any problem then do share it here.

answered Feb 5 by Roshni
• 600 points

Related Questions In Python

0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
1,597 views
+1 vote
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
4,272 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,350 points
190 views
0 votes
1 answer

How to split a string into a list?

You can use the function  text.split() This should be ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 57,530 points
124 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,230 points
214 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 939 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'list' and 'int'

Hey, @William For me the code is working ...READ MORE

answered Mar 11 in Python by Roshni
• 600 points
279 views