簡體   English   中英

Python:插入 x、y、z 數據

[英]Python:Interpolate x, y, z data

數據

 ,1,2,3
5,10,11,12
6,13,14,15
7,16,17,18

數據在熊貓 df 中

1,2,3 是 x 坐標(列標題) 5,6,7 是 y 坐標(索引)

10-18是z坐標

我需要插入值,例如 x=2.5 和 y=6.3

讓我們使用reindexinterpolate

#read dataframe in 
df = pd.read_clipboard(sep=',', index_col=[0])

#change dtype of column headers to floats
df.columns= df.columns.astype('float')

#Use reindex and interpolate to fill values along each axis
df_out = df.reindex([5,6,6.3,7]).interpolate(method='index', axis=0)\
           .reindex([1,2,2.5,3],axis=1).interpolate(method='index', axis=1)

#Output resulting dataframe
df_out

輸出:

      1.0   2.0   2.5   3.0

5.0  10.0  11.0  11.5  12.0
6.0  13.0  14.0  14.5  15.0
6.3  13.9  14.9  15.4  15.9
7.0  16.0  17.0  17.5  18.0

和,

df_out.loc[6.3, 2.5]

輸出:

15.399999999999999

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM