将带有日期列的Pandas数据框转换为Vaex数据框。

问题描述 投票:1回答:1

我正在尝试做以下工作

  1. 加载一些带有字符串列的数据
measurement_df = pd.read_csv('data/tag_measurements/all_measurements.csv')
measurement_df.head(3)
measurement_df
>> prints
.  timestamp               tag_1      tag_2        tag_3    
0   2018-01-01 11:09:00 0.729193    -0.236627   -1.968651   
1   2018-01-02 05:56:00 -2.812988   0.394632    -1.151147   
2   2018-01-03 00:37:00 0.363185    -0.089076   -1.509133   

此时时间戳列的类型为str。

type(measurement_df.iloc[0]['timestamp'])
>> prints
str
  1. 转换为Vaex
vdf = vx.from_pandas(measurement_df)
vdf.head(3)
>> prints
#           tag_1          tag_2                  tag_3           index
0   0.7291933972260769  -0.2366268009370677  -1.9686509728501898    0
1   -2.8129876800434737 0.3946317890604529   -1.1511473058592252    1
2   0.3631852302577519  -0.08907562484360453 -1.5091330993605443    2 

不知为何,我失去了时间戳一栏。有什么办法可以解决这个问题吗?

python pandas dataframe timestamp vaex
1个回答
0
投票

如果你想保留数据时间格式,特别是在读取CSV时,我建议你这样做。

df = pd.read_csv('myfile.csv', parse_dates=['datetime_col_1', 'datetime_col_2'])

你也可以这样做。

df = vaex.read_csv('myfile.csv', parse_dates=['datetime_col_1', 'datetime_col_2'])

它是一样的,因为它是在后台使用pandas方法。

© www.soinside.com 2019 - 2024. All rights reserved.