Skip to content

Commit

Permalink
Merge pull request #1 from yangleir/main
Browse files Browse the repository at this point in the history
time format edit
  • Loading branch information
dspelaez authored Dec 5, 2024
2 parents d6cf2a3 + dddfc9d commit ddb7e08
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ewdm/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ def read_dataset(self):
data = pd.read_csv(
self.fname, names=columns, header=None, skiprows=1
)
# combine the desired date-time columns and convert them to datetime


# Format the 'msec' column to be three digits
data['msec'] = data['msec'].apply(lambda x: f'{int(x):03}')
# print(data['msec'])

# Combine the desired date-time columns and convert them to datetime
# Here, we concatenate the time components and ensure the millisecond part is correctly formatted
data["time"] = pd.to_datetime(
data[columns[:7]].astype(str).agg(','.join, axis=1),
format="%Y,%m,%d,%H,%M,%S,%f"
data['year'].astype(str) + '-' +
data['month'].astype(str) + '-' +
data['day'].astype(str) + ' ' +
data['hour'].astype(str) + ':' +
data['min'].astype(str) + ':' +
data['sec'].astype(str) + '.' +
data['msec'], # Concatenate using three-digit milliseconds
format="%Y-%m-%d %H:%M:%S.%f" # Use .%f to parse the millisecond part
)

data = data.drop(columns=columns[:7])

# convert to xarray and add metadata
Expand Down

0 comments on commit ddb7e08

Please sign in to comment.