Joey
Joey

Reputation: 934

exporting a list of lists to csv in python

I want to export a list of lists to a csv file. However, the csv file is not showing any of the data.

Initially I have 30 rows of 'I' data and one row of 'R' data.

I run my algorithm to obtain peak areas when R is plotted against I{i}. This gives me 30 sets of data each with three columns as follows:

>      0          1             2
>     0   3053.6   105000.0  -5217775.735
>     1   3015.9    81892.0  -4013311.400
>     2   2962.8    98694.0  -2050799.050
>     3   2936.2    67884.0  -1140645.600
>     4   2906.3  2530000.0 -22099575.600
>     5   2871.5   102000.0   -653778.650
>     6   2777.9     8482.4    -68580.440
>     7   2719.3    11768.0    -91285.610
>     8   2625.0     5902.5    -40623.500
>     9   2599.3     5304.7    -69163.680
>     10  2573.5    18009.0   -170745.690
>     11  1538.0    12694.0   -965128.025
>     12  1467.7     9279.2   -144139.995
>     13  1451.4    21626.0   -280386.495
>     14  1329.8     7739.9    -63603.430
>     15  1173.9     8096.7    -66836.410
>     16   966.3    10964.0   -101197.010
>     17   799.2    32662.0   -305534.340
>     18   164.5   124000.0  -1579972.665

Find_peaks is my function as described above.

result =[]

for i in range(1,31):
    result.append(pd.DataFrame((find_peaks(df1['R'], df1['I {}'.format(i)])), index = None))

for i in range(1,31):
    df2 = pd.DataFrame(result[i])
    df2.to_csv('Output.csv')

I'm not sure what I am doing wrong.

Upvotes: 0

Views: 1264

Answers (1)

jezrael
jezrael

Reputation: 862406

You can try concat this output dataframes to one:

import pandas as pd

result = []

for i in range(1,31):
    result.append(pd.DataFrame((find_peaks(df1['R'], df1['I {}'.format(i)])), index = None))
    df2 = pd.concat(result)

print df2.head()
df2.to_csv('Output.csv')

Upvotes: 1

Related Questions