trpc | π§ββοΈ Move Fast and Break Nothing End-to-end typesafe APIs made easy | REST library
kandi X-RAY | trpc Summary
Support
Quality
Security
License
Reuse
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
trpc Key Features
trpc Examples and Code Snippets
Trending Discussions on trpc
Trending Discussions on trpc
QUESTION
I have imported some data that looks like a list of items because of square brackets, but is really just strings.
I used Pandas df['column name'].values.tolist()
to convert each row to a list:
[
"41885593, 'DNV GL Group AS', 'DNVGI', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)",
"48551738, 'Vigeo SAS', 'VIGEO', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)",
"50177826, 'Climate Bonds Initiative', 'CLIBON', 'TRPC', '3rd Party Certifier', datetime.date(2017, 2, 28)"
]
But each item within the list has remained a string. I need each covert so they are actually separate items within a list rather than just strings. If I use list(item)
to convert to a list, it breaks it down to each character as part of the list.
so if it worked, i would have a list like:
mystuff = [
"41885593, 'DNV GL Group AS', 'DNVGI', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)",
"48551738, 'Vigeo SAS', 'VIGEO', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)",
"50177826, 'Climate Bonds Initiative', 'CLIBON', 'TRPC', '3rd Party Certifier', datetime.date(2017, 2, 28)"
]
And if I ran a for loop over it:
for item in mystuff:
print(item)
print("*********")
The output would be:
41885593, 'DNV GL Group AS', 'DNVGI', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)
*********
48551738, 'Vigeo SAS', 'VIGEO', 'SNPC', '2nd Party Consultant', datetime.date(2017, 2, 28)
*********
50177826, 'Climate Bonds Initiative', 'CLIBON', 'TRPC', '3rd Party Certifier', datetime.date(2017, 2, 28)
*********
ANSWER
Answered 2020-Mar-20 at 01:58Each item of your mystuff
list is a str
that represents comma-separated elements.
Solution based on the split
method of str
:
mystuff = [x.split(', ') for x in mystuff]
If you want mystuff
as a list of items :
mystuff = sum(map(lambda x: x.split(', '), mystuff), [])
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install trpc
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kitsβ
Save this library and start creating your kit
Share this Page