[英]python pandas dataframe unique values appending 'L' to data values
I am running a python file as CGI which is reading a CSV into pandas dataframe. 我正在运行一个python文件作为CGI,它正在将CSV读入pandas数据帧。 Problem is when I try to get unique values of columns that have just integer values, I get an extra appended 'L' to the data values.
问题是当我尝试获得只有整数值的列的唯一值时,我得到一个额外的“L”附加到数据值。
Here's the code. 这是代码。
def Main():
formData = cgi.FieldStorage()
fileName = str(formData.getvalue('file'))
field = str(formData.getvalue('field'))
df = fileRead.readFile(fileName)
unique = pd.unique(df[field])
print unique.tolist()
Here's the output: 这是输出:
[1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L]
[1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L ,26L,27L,28L]
This works fine with columns that have float values or text values. 这适用于具有浮点值或文本值的列。
[25.9, 29.5, 27.9, 29.9, 30.9, 28.9, 84.9, 82.9, 35.9, 31.5, 31.0, 30.0, 36.9, 41.9, 40.5, 43.9, 37.5, 37.9, 44.5, 38.9, 45.8, 41.0]
[25.9,29.5,27.9,29.9,30.9,28.9,84.9,82.9,35.9,31.5,31.0,30.0,36.9,41.9,40.5,43.9,37.5,37.9,44.5,38.9,45.8,41.0]
BTW, fileRead is just another file which reads the CSV to dataframe. BTW,fileRead只是另一个将CSV读取到数据帧的文件。
df = pd.read_csv(path)
Here "L" refers to "Long". 这里“L”指的是“长”。 It shouldn't affect your code other than taking more memory.
除了占用更多内存之外,它不应该影响您的代码。
example: 1L + 2 = 3L 例如:1L + 2 = 3L
Also, rather than doing: 而且,而不是做:
unique = pd.unique(df[field])
try this 试试这个
unique = df.drop_duplicates('field')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.