I need your help about read_fwf in python pandas -


the example of text file picture enter image description here

according file, direction of data changed after word 'chapter' in other word, direction of reading changed horizontal vertical.

in order solve big problem, find read_fwf in pandas module , apply failed.

linefwf = pandas.read_fwf('file.txt', widths=[33,33,33], header=none, nwors = 3) 

the gap between categories(chapter, title, assignment) 33.

but command(linefwf) prints of pages line includes horizontal categories such title, date, reservation blank lines.

please, want know 'how export vertical data only'

let me take stab in dark: wish turn table column (aka "vertical category"), ignoring other columns?

i didn't have precise text, guesstimated it. column widths different yours ([11,21,31]) , omitted nwors argument (you meant use nrows, it's superfluous in case). while column spec isn't precise, few seconds of fiddling left me workable dataframe:

enter image description here

this pretty typical of read-in datasets. let's clean slightly, giving real column names, , taking out separator rows:

df.columns = list(df.loc[0]) df = df.ix[2:6] 

this has following effect:

enter image description here

leaving df as:

enter image description here

we won't take time reindex rows. assuming want value of column, can indexing:

df['chapter'] 

yields:

2    1-1 3    1-2 4    1-3 5    1-4 6    1-5 name: chapter, dtype: object 

or if want not pandas.series native python list:

list(df['chapter']) 

yields:

['1-1', '1-2', '1-3', '1-4', '1-5'] 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -