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, 2020 in Python by Parul
• 130 points

edited Feb 5, 2020 by Gitika 926 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, 2020 by Roshni
• 10,480 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
3,477 views
+1 vote
2 answers

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

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

answered Oct 28, 2020 in Python by Anurag
12,425 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

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

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,117 views
+1 vote
8 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
36,050 views
0 votes
1 answer

how to solve this IndexError: list index out of range in python and streamlit?

Hi,  @Erick, To solve the “index error: list ...READ MORE

answered Sep 25, 2020 in Python by Roshni
• 10,480 points
28,473 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP