0

I have a dataframe in a data file:

test_num|minval|maxval|test_name|unit|pin|condit
5|-0.0015|0.0015|Uoffset|V|1|Ucc=Uee=15V
6|-0.0015|0.0015|Uoffset|V|1|Ucc=Uee=15V
7|-0.0015|0.0015|Uoffset|V|2|Ucc=Uee=15V
8|-0.0015|0.0015|Uoffset|V|2|Ucc=Uee=15V

When the data is read, the column 'unit' becomes floating point:

info=pd.read_csv('pdinfo.dat',sep='|',index_col='test_num')
print(info)

5        -1.500000e-03  1.500000e-03    Uoffset V  1.0  Ucc=Uee=15V
6        -1.500000e-03  1.500000e-03    Uoffset V  1.0  Ucc=Uee=15V
7        -1.500000e-03  1.500000e-03    Uoffset V  2.0  Ucc=Uee=15V
8        -1.500000e-03  1.500000e-03    Uoffset V  2.0  Ucc=Uee=15V

I can't make it integer, because in various data files there may be 'pin' values like Q_11 or A3. How to assert the data in certain column to be a string?

2
  • 1
    use pd.read_csv('pdinfo.dat',sep='|',index_col='test_num', dtype={'unit':str}) Commented Sep 26, 2017 at 8:50
  • it is dupe, so only comment Commented Sep 26, 2017 at 8:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.