这是我的 CSV 原始数据:
N_Truc |信息|价值|KK|小时 | IEx
3002 |N-O-O-N-N O-N-N-N-N-N-C | 0 1 0 |一个| 21:27:24.418 | 2
3002 |N-O-O-N-N O-N-N-N-N-N-C | 1 1 0 |一个 | 21:27:24.169 | 3
3211 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5774
3211 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5775
3211 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.351 | 5776
3212 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5777
3212 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5778
3212 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.351 | 5779
3213 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5780
3213 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5781
3213 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.352 | 5782
3214 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5783
3214 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5784
3214 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.354 | 5785
3315 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5786
3315 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5787
3315 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.354 | 5788
3316 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5789
3316 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5790
3316 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.354 | 5791
3317 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5792
3317 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5793
3317 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 |一个| 21:27:26.354 | 5794
3418 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5795
3418 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 | | 21:28:44.080 | 5796
3418 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 | | 21:28:49.787 | 5797
3419 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5798
3419 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 | | 21:28:44.081 | 5799
3419 | N-O-O-N-N O-N-N-N-N-N-C | 0 0 0 | | 21:28:49.787 | 5800
3420 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5801
3420 |N-O-O-N-N O-N-N-N-N-N-C | 0 0 1 | | 01:00:00.000 | 5802
3420 | N-O-O-N-N O-N-N-N-N-N-C | 1 0 0 |一个 | 21:27:26.355 | 5803
我使用 Python3。 我读了我的文件,有:
df = pd.read_csv(filename, sep='|')
抑制 ' ' 字符
df.columns = df.columns.str.replace(' ', '')
清理'--','-',如果在'--'之后我们有超过2位数字
df = df.replace(r'--\\d{2,}', ' 0 ', regex=True).\ replace(r'--', '', regex=True).replace(r'-', '', regex=True)
然后,对于下一次治疗,我正在使用地图。这里有一个例子:
for num_ech in range(1, 50): # Test if column exists if 'IEx'+str(num_ech) in df.columns: df['I_Truc'+str(num_ech)] = df['Ex'+str(num_ech)].map(df2.set_index('IEx')['N_Truc'])
显示我的数据框(Python3 / PyQt)
` self.model = PandasTableModel(self.df)
self.tableView.setModel(self.model)
` 然后,我所有的数字数据字段都显示为浮点数(即:1234.0),我想显示为整数:1234(对 1234.0)或 5803(对 5803.0)
拜托,你有什么想法吗?