pandas - Creating A Dataframe From a Previously Read In Text File in Python -


i new python, please forgive me if way have written code isn't pretty. but, trying create dataframe single column of values loaded in text file because need able have index column of data. here example of have:

import pandas pd file = open('sample.txt','r') data in(raw.strip().split() raw in file):     y = data[5] 

now, want able turn y variable list of values data frame pandas can have index.

here example of values of y variable like:

553.01 551.37 597.75 635.81 720.56 766.11 

here how it.

import pandas pd data =[] open('test.txt', 'r+') f:     line in f:        data.append(line.strip()) #create dataframe df = pd.dataframe(data) #change column name df.columns = ['value'] #view data df.head() 

i hope result need.


Comments