1

I have 10000 data that I'm sorting into a dictionary and then exporting that to a csv using pandas. I'm sorting temperatures, pressures and flow associated with a key. But when doing this I find: https://i.stack.imgur.com/pWWBb.jpg but I want something like this:https://i.stack.imgur.com/aYDmh.jpg

I'm transposing my dataframe so the index can be rows but in this case I want only 3 rows 1,2, & 3, and all the data populate those rows.

flow_dictionary = {'200:P1F1':[5.5, 5.5, 5.5]}
pres_dictionary = {'200:PT02':[200,200,200],
                   '200:PT03':[200,200,200],
                   '200:PT06':[66,66,66],
                   '200:PT07':[66,66,66]}
temp_dictionary = {'200:TE02':[27,27,27], 
                   '200:TE03':[79,79,79],
                   '200:TE06':[113,113,113],
                   '200:TE07':[32,32,32]}

df = pd.DataFrame.from_dict(temp_dictionary, orient='index').T

df2 = pd.DataFrame.from_dict(pres_dictionary, orient='index').T

df3 = pd.DataFrame.from_dict(flow_dictionary, orient='index').T

df = df.append(df2, ignore_index=False, sort=True)

df = df.append(df3, ignore_index=False, sort=True)

df.to_csv('processedSegmentedData.csv')

SOLUTION:

df1 = pd.DataFrame.from_dict(temp_dictionary, orient='index').T

df2 = pd.DataFrame.from_dict(pres_dictionary, orient='index').T

df3 = pd.DataFrame.from_dict(flow_dictionary, orient='index').T

df4 = pd.concat([df1,df2,df3], axis=1)

df4.to_csv('processedSegmentedData.csv')

user11886521
  • 83
  • 1
  • 6
  • 1
    What is your question ? – Benoit Drogou Aug 08 '19 at 18:50
  • Please look at [How to create good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and provide a [mcve] including sample data (as text, not as a picture) and sample output – G. Anderson Aug 08 '19 at 18:53
  • Without _sample_ input and preferred output, it's hard to test any solutions against what you're trying to achieve given your inputs – G. Anderson Aug 08 '19 at 19:05
  • @G.Anderson How's this? – user11886521 Aug 08 '19 at 19:41
  • I think I was writing df1 instead of df4 when I was using concat but this worked for me for future users: df1 = pd.DataFrame.from_dict(temp_dictionary, orient='index').T df2 = pd.DataFrame.from_dict(pres_dictionary, orient='index').T df3 = pd.DataFrame.from_dict(flow_dictionary, orient='index').T df4 = pd.concat([df1,df2,df3], axis=1) df4.to_csv('processedSegmentedData.csv') – user11886521 Aug 08 '19 at 20:27

0 Answers0