Reputation: 45
I have a txt file with three features:
file_name.txt:
[{"x":1599235200000,"isValid":true,"y":10830027},
{"x":1599321600000,"isValid":true,"y":10883502},
{"x":1599408000000,"isValid":true,"y":10915511}]
Using python read the txt file and make it into dataframe.
The output I wish I have is only x and y: x is the timestamp and should be 1599235200.000 --> (2020, 9, 4, 16, 0) y is the numerical value, and the output should convert into the dataframe.
dataframe:
x y
2020-09-04 10830027
2020-09-05 10883502
2020-09-06 10915511
Upvotes: 0
Views: 67
Reputation: 6748
It looks like JSON data. pandas has a method read_json
to read JSON files.
df = pd.read_json('file_name.txt')
df['x'] = pd.to_datetime(df['x'])
df
Output:
x isValid y
0 1970-01-01 00:26:39.235200 True 10830027
1 1970-01-01 00:26:39.321600 True 10883502
2 1970-01-01 00:26:39.408000 True 10915511
Upvotes: 2