Parse Python List To Pandas Dataframe
I have an array that has values separated by '|'. I would like to parse it to a pandas data frame. import pandas as pd arr = ['19345360853|5264654|100530|2017-01-07', '1934536
Solution 1:
First, convert to two dimensional list
arr = [a.split("|") for a in arr]
Second, convert to pandas dataframe
data = pd.DataFrame(arr,columns=['Id','Code_A','Code_B','Reg_Date'])
Id Code_A Code_B Reg_Date
01934536085352646541005302017-01-07119345360853135183711005302018-10-08
Convert column Reg_Date using astype
(Ref: astype)
a =pd.DataFrame(arr,columns=['Id','Code_A','Code_B','Reg_Date'])
a['Reg_Date'] = a['Reg_Date'].astype('datetime64[ns]')
Post a Comment for "Parse Python List To Pandas Dataframe"