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 181 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
• 6,860 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
2,052 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 in Python by Anurag
5,952 views
0 votes
1 answer
0 votes
1 answer
+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 1,593 views
0 votes
0 answers
+4 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,800 points
1,205 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 24 in Python by Roshni
• 6,860 points
1,623 views
0 votes
1 answer

How to dynamically load a module in Python?

Hi, Dynamic loading is where we do not ...READ MORE

answered Jun 26 in Python by Roshni
• 6,860 points
214 views