'From DataFrame to int, with single column

  1. I'm trying to convert a csv file that is in pandas data frame type, into an integer.
  2. I already tried pandas astype way
  3. Any second look or advice is well received
import csv
import pandas as pd
from pandas import DataFrame

col_list = ["Solicitud"]
    daf = pd.read_csv(r"C:\Users\N\inapi_scraper\solicitudes_v0.csv", usecols=[0], names=['Solicitud'], header=None)#, usecols=col_list)
    datf=daf[0:737]
    df[datf] = df[datf].astype(dtype=int)

I always receive this error:

TypeError: 'type' object is not subscriptable



Solution 1:[1]

datf is already a dataframe and not a mask (and df does not exist?)

datf = daf.loc[0:737].astype(int)

Use .iloc or loc depends on your index.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien