简体   繁体   中英

Creating a curve from dataframe

I have a dataframe that looks like this :

                  0        1       2     ...         147      148      149
Columns 0       190.2    190.5   189.9   ...       146.7    146.4    146.1
Values  0    -49.3892 -47.0297 -39.528   ...    -30.7926 -30.7561  -30.719
Columns 1       190.2    190.5   189.9   ...       146.7    146.4    146.1
Values  1    -49.3892 -47.0297 -39.528   ...    -30.7926 -30.7561  -30.719
Columns 2       190.2    190.5   189.9   ...       146.7    146.4    146.1

I want to create a curve for every pair Columns # and Value # . The dataframe has 3478 rows so 1738 pairs of data.

I have tried a for loop that looks like:

 import matplotlib.pyplot as plt
 nline2 = len(df2.index)
 for i in range (0,(nline-2),2)
    x_data = df2.values[[i]]
    y_data = df2.values[[(i+1)]]
    plt.plot(x_data,y_data)

But i get an error message : TypeError: unhashable type: 'numpy.ndarray'

Note that i am trying to plot only to see what i get, the ultimate goal of this to calulate the area under the curve for each pair and add it for all pairs. Hense the for loop .

UPDATE

I think found the source of the problem, the rows calles Columns # are used as headers and not scalar values. I tried df2.iat[index,columns] but without success.

To change the values of the Columns # rows, I used:

df2 = df2.apply(pd.to_numeric)

Then for teh purpose of plotting only the first pair:

i = 0

x_data = df2.values[[i]]
y_data = df2.values[[(i+1)]]

#line = plt.plot(x_data, y_data)
#plt.setp(line, color = 'r', linewidth = 2.0)

line = plt.Line2D(x_data, y_data,linewidth = 2)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM