python - Pandas - Convert dictionary to dataframe - keys as columns -


i have folder .csv files contain timeseries in following format:

1   0.950861 2   2.34248 3   2.56038 4   3.46226 ... 

i access these textfiles looping on folder containing files , passing each textfile dictionary:

data_dict = {textfile: pd.read_csv(textfile, header=3, delim_whitespace=true, index_col=0) textfile in textfiles} 

i want merge columns, contain data next each other dictionary keys index (pathname of textfiles). have same row number.

so far tried passing dictionary pd.dataframe this:

df = pd.dataframe.from_dict(data_dict, orient='index') 

actually, orientation needs default 'columns', results in error: value error: if using scalar values, must pass index

if so, wrong result: excel_output

this how pass frame excel:

writer = pd.excelwriter("output.xls") df.to_excel(writer,'data', index_label = 'data', merge_cells =false) writer.save() 

i think error must in passing dictionary dataframe. tried pd.concat/merge/append nothing returns right result.

thanks in advance!

iiuc can try list comprehension concat:

data_list = [pd.read_csv(textfile, header=3, delim_whitespace=true, index_col=0)               textfile in textfiles] print (pd.concat(data_list, axis=1)) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -