3

我正在尝试执行以下操作

  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 

不知何故,我失去了时间戳列。有什么想法可能会出错吗?

4

1 回答 1

2

如果您想保留日期/时间格式,尤其是在阅读 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 方法。

于 2020-06-10T08:52:46.770 回答