简体   繁体   中英

How to determine the datatype of columns in a csv file in python?

I am trying to determine the data type of all the columns in a csv file. The code is:

df = pd.read_csv('accepted.csv')
for name, dtype in df.dtypes.iteritems():
        print("Column Name: ",name," ||| ","Data Type : ", dtype)

Now the problem I am facing is that it gives float64 for most of the columns and 0 for some. How can I get the original data type?

@Gandharv this code is working fine, i got the correct data types for each features However you can directly view the datatypes using.dtypes(): This returns a Series with the data type of each column. Why do you need to use for loop for this since we've a function to do it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM