nick_fh_cl
nick_fh_cl

Reputation: 45

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

Upvotes: 0

Views: 172

Answers (1)

Corralien
Corralien

Reputation: 120409

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.

Upvotes: 1

Related Questions