Convert list of multiple strings into a Python data frame

Nirali Khoda

I have a list of string values I read this from a text document with splitlines. which yields something like this

       X = ["NAME|Contact|Education","SMITH|12345|Graduate","NITA|11111|Diploma"]

I have tried this

for i in X:
    textnew = i.split("|")
    data[x] = textnew

I want to make a dataframe out of this

    Name     Contact      Education
    SMITH     12345        Graduate
    NITA      11111        Diploma
Darren Christopher

You can read it directly from your file by specifying a sep argument to pd.read_csv.

df = pd.read_csv("/path/to/file", sep='|')

Or if you wish to convert it from list of string instead:

data = [row.split('|') for row in X]
headers = data.pop(0) # Pop the first element since it's header
df = pd.DataFrame(data, columns=headers)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

in python how do i convert a list of strings to pandas data frame

How to convert a list of strings to data frame?

How Convert a list to a data frame Python

How to convert a list to a data frame in python?

Python - Convert json list to a data frame

how to convert multiple strings into list using python

How to parse a list of multiple list and convert it to data frame in R?

Convert a list to a data frame

split strings and convert to data frame

Convert Spark Data frame to multiple list with one column as key

Pandas: Convert single row in data frame to a list with multiple dimensions

Convert a list to data.frame with multiple columns in R

R convert list with multiple string lengths to data frame

Convert strings to list Python

How to convert list of strings into two column data frame base on the subsequent string in the list

Convert list into a pandas data frame

convert a list to data frame in R

Convert json list to data frame

Convert character list to data frame

Convert List to Data frame for analysis

Convert a patterned list into data frame

convert nested list to data frame

Convert dictionary with the list to data frame using pandas python 3

Convert a standard python key value dictionary list to pyspark data frame

Python - Replace strings in a data frame

Convert pandas data frame to JSON with strings separated

Python: Converting a list of strings into pandas data-frame with two columns a and b, corresponding to odd and even strings respectively

R - Convert list of list into data frame

convert a list to data frame without messing with data