目前我有一个看起来像这样的 pandas 数据框(它最初来自一个大的 csv 文件,我包含了一个小片段)
ds = pd.DataFrame([('2020-312T00:00:00.746', 2.466000e-15, 2.330500e-15, 2.949800e-15, 7.497400e-15, 3.682900e-15, 6.375300e-15),
('2020-312T00:00:01.746', 1.406300e-14, 1.319700e-14, 6.588400e-15, 5.245300e-15, 4.462600e-15, 6.375300e-15),
('2020-312T00:00:02.746', 9.389400e-15, 7.542200e-15, 5.433000e-15, 2.355100e-15, 7.388700e-15, 3.852900e-15),
('2020-312T00:00:03.746', 5.252700e-15, 4.338100e-15, 6.588400e-15, 5.245300e-15, 2.934300e-15, 6.375300e-15),
('2020-312T00:00:04.746', 5.252700e-15, 9.345600e-15, 3.340000e-15, 5.245300e-15, 8.766700e-15, 4.640600e-15)],
columns=['Epoch', ' Freq_1.12E+04', 'Freq_1.25E+04', 'Freq_1.41E+04', 'Freq_1.58E+04', 'Freq_1.77E+04',
'Freq_1.98E+04'])
ds
我使用
new_ds = ds.to_xarray()
将此数据帧转换为 xarray,它打印出一个数据集,如下所示
--
我想通过将 Epoch 设置为索引来更改此数据集,然后将坐标更改为 Epoch 和频率。并将维度更改为历元和频率(分别为 x 轴和 y 轴)。我该怎么办?
您只需将纪元设置为索引即可
import pandas as pd
import xarray as xr
ds = pd.DataFrame([
('2020-312T00:00:00.746', 2.466000e-15, 2.330500e-15, 2.949800e-15, 7.497400e-15, 3.682900e-15, 6.375300e-15),
('2020-312T00:00:01.746', 1.406300e-14, 1.319700e-14, 6.588400e-15, 5.245300e-15, 4.462600e-15, 6.375300e-15),
('2020-312T00:00:02.746', 9.389400e-15, 7.542200e-15, 5.433000e-15, 2.355100e-15, 7.388700e-15, 3.852900e-15),
('2020-312T00:00:03.746', 5.252700e-15, 4.338100e-15, 6.588400e-15, 5.245300e-15, 2.934300e-15, 6.375300e-15),
('2020-312T00:00:04.746', 5.252700e-15, 9.345600e-15, 3.340000e-15, 5.245300e-15, 8.766700e-15, 4.640600e-15)
], columns=['Epoch', 'Freq_1.12E+04', 'Freq_1.25E+04', 'Freq_1.41E+04', 'Freq_1.58E+04', 'Freq_1.77E+04', 'Freq_1.98E+04'])
ds = ds.set_index('Epoch')
xds = ds.to_xarray()
xds
这给了你