猿问

大熊猫清理数据框

我目前正在学习熊猫并且在清理我的数据框时遇到问题:


"TIMESTAMP","RECORD","WM1_u_ms","WM1_v_ms","WM1_w_ms","WM2_u_ms","WM2_v_ms","WM2_w_ms","WS1_u_ms","WS1_v_ms"

"2018-04-06 14:31:11.5",29699805,2.628,4.629,0.599,3.908,7.971,0.47,2.51,7.18

"2018-04-06 14:31:11.75",29699806,3.264,4.755,-0.095,2.961,6.094,-0.504,2.47,7.18

"2018-04-06 14:31:12",29699807,1.542,5.793,0.698,4.95,4.91,0.845,2.18,7.5

"2018-04-06 14:31:12.25",29699808,2.527,5.207,0.012,4.843,6.285,0.924,2.15,7.4

"2018-04-06 14:31:12.5",29699809,3.511,4.528,1.059,2.986,5.636,0.949,3.29,5.54

"2018-04-06 14:31:12.75",29699810,3.445,3.957,-0.075,3.127,6.561,0.259,3.85,5.45

"2018-04-06 14:31:13",29699811,2.624,5.238,-0.166,3.451,7.199,0.242,3.94,6.24


df = pd.read_csv(FilePath,parse_dates=True)  #read the csv file and save it into a variable

df = df.drop(['RECORD'],axis=1)我目前正在学习熊猫并且在清理我的数据框时遇到问题:


我不明白为什么 Pandas 将部分识别为 float64,而将其他部分识别为对象。你们有什么线索吗?因此,我开始尝试自己转换列:

df['TIMESTAMP'] = pd.to_datetime(df['TIMESTAMP'])
df['WM1_u_ms':] = df.iloc[:, df.columns != 'TIMESTAMP'].values.astype(float)

但我收到一个错误:

cannot do slice indexing on <class 'pandas.core.indexes.range.RangeIndex'> with these indexers [WM1_u_ms] of <class 'str'>

为什么熊猫不能从一开始就正确读取 .dat 文件,以及转换它是我的错。在下一个 stemp 中,我想通过 df.interpolate() 进行插值以清除 nan

谢谢你的帮助!


MM们
浏览 245回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答