Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:12:13+00:00 2026-06-10T08:12:13+00:00

I have a #-separated file with three columns: the first is integer, the second

  • 0

I have a #-separated file with three columns: the first is integer, the second looks like a float, but isn’t, and the third is a string. I attempt to load this directly into python with pandas.read_csv

In [149]: d = pandas.read_csv('resources/names/fos_names.csv',  sep='#', header=None, names=['int_field', 'floatlike_field', 'str_field'])

In [150]: d
Out[150]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1673 entries, 0 to 1672
Data columns:
int_field          1673  non-null values
floatlike_field    1673  non-null values
str_field          1673  non-null values
dtypes: float64(1), int64(1), object(1)

pandas tries to be smart and automatically convert fields to a useful type. The issue is that I don’t actually want it to do so (if I did, I’d used the converters argument). How can I prevent pandas from converting types automatically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:12:14+00:00Added an answer on June 10, 2026 at 8:12 am

    I think your best bet is to read the data in as a record array first using numpy.

    # what you described:
    In [15]: import numpy as np
    In [16]: import pandas
    In [17]: x = pandas.read_csv('weird.csv')
    
    In [19]: x.dtypes
    Out[19]: 
    int_field            int64
    floatlike_field    float64  # what you don't want?
    str_field           object
    
    In [20]: datatypes = [('int_field','i4'),('floatlike','S10'),('strfield','S10')]
    
    In [21]: y_np = np.loadtxt('weird.csv', dtype=datatypes, delimiter=',', skiprows=1)
    
    In [22]: y_np
    Out[22]: 
    array([(1, '2.31', 'one'), (2, '3.12', 'two'), (3, '1.32', 'three ')], 
          dtype=[('int_field', '<i4'), ('floatlike', '|S10'), ('strfield', '|S10')])
    
    In [23]: y_pandas = pandas.DataFrame.from_records(y_np)
    
    In [25]: y_pandas.dtypes
    Out[25]: 
    int_field     int64
    floatlike    object  # better?
    strfield     object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a txt file with columns separated by tabs and based on that
I have a text file containing words separated by newline , like the following
I have a comma-separated file, with the first column as a date of the
I have semicolon-separated .dat file and I want to read that file and store
I have a tab-separated data file with a little over 2 million lines and
Assume that I have a text file separated by colons. I understand how to
I have a method that reads data from a comma separated text file and
I have a text file (tab separated) which consist of 17 column. I would
I have Text file that contains data separated with a comma , . How
I have a file with great amount of numbers,each number is separated by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.