I am running a python file as CGI which is reading a CSV into pandas dataframe. 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.
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]
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]
BTW, fileRead is just another file which reads the CSV to dataframe.
df = pd.read_csv(path)
Here "L" refers to "Long". It shouldn't affect your code other than taking more memory.
example: 1L + 2 = 3L
Also, rather than doing:
unique = pd.unique(df[field])
try this
unique = df.drop_duplicates('field')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.