판 objet 목록 datetime serie 날짜/시간 인덱스

0

질문

나 필드를 사용하여 매개변수에 python-동 방법을 검색할 수 있도록 api 를 일부 데이터에동 방법문을 원하는@에 타임스탬프 iso 형식에서 사용하기 위해 판 데이터 프레임.

fields = \
    [{
      "field": "@timestamp",
      "format": "strict_date_optional_time"
    }]

기본적으로동 방법을 반환에 결과를 배열 목록 형식에서 볼 수 있듯이 doc:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html

The fields response always returns an array of values for each field, even when there is a single value in the _source. 

이로 인해 그 결과 데이터 프레임이 포함되체 목록을 세리할 수 없는 구문 분석하 datetime 세리에 의해 기존의 방법이 있습니다.

Name: fields.@timestamp, Length: 18707, dtype: object
0       [2021-11-04T01:30:00.263Z]
1       [2021-11-04T01:30:00.385Z]
2       [2021-11-04T01:30:00.406Z]
3       [2021-11-04T01:30:00.996Z]
4       [2021-11-04T01:30:01.001Z]
                   ...            
8368    [2021-11-04T02:00:00.846Z]
8369    [2021-11-04T02:00:00.894Z]
8370    [2021-11-04T02:00:00.895Z]
8371    [2021-11-04T02:00:00.984Z]
8372    [2021-11-04T02:00:00.988Z]

하려고 할 때문 분석 시리즈를 datetime serie:

pd.to_datetime(["fields.@timestamp"])

결과:

TypeError: <class 'list'> is not convertible to datetime

내 사용하여 필요한 경우 많은 날짜 형식 및 필드를 매개변수에 맞는 매우 잘를 쿼리하는 여러 포맷하지만,에 나열된 개체 datetime 문자열은 어려운 것들입니다.

dataframe datetime elasticsearch pandas
2021-11-18 16:37:23
1

최고의 응답

1

여기에서 문제점의 항목 fields.@timestamp 실제로 목록입니다.

그래서 당신이 할 수 있다:

fields['timestamp'] = fields['timestamp'].str[0]

추출일부터 목록 다음 사용하 pd.to_datetime:

fields['timestamp'] = pd.to_datetime(fields['timestamp'])
2021-11-18 17:01:03

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................