我想導入下面的csv作爲字符串而不是int64。熊貓read_csv自動將其轉換爲int64,但我需要此列作爲字符串。作爲字符串導入熊貓dataframe列不是int
ID
00013007854817840016671868
00013007854817840016749251
00013007854817840016754630
00013007854817840016781876
00013007854817840017028824
00013007854817840017963235
00013007854817840018860166
df = read_csv('sample.csv')
df.ID
>>
0 -9223372036854775808
1 -9223372036854775808
2 -9223372036854775808
3 -9223372036854775808
4 -9223372036854775808
5 -9223372036854775808
6 -9223372036854775808
Name: ID
不幸的是使用轉換器給出了相同的結果。
df = read_csv('sample.csv', converters={'ID': str})
df.ID
>>
0 -9223372036854775808
1 -9223372036854775808
2 -9223372036854775808
3 -9223372036854775808
4 -9223372036854775808
5 -9223372036854775808
6 -9223372036854775808
Name: ID
這是這個問題的一個副本:http://stackoverflow.com/questions/13250046/pandas-csv-import-keep-leading-zeros-in-a-列 –
這明確強調了轉換器無法工作的問題。所以,除了上面提到的問題之外,它仍然是有用的。 –