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 8957907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:06:06+00:00 2026-06-15T15:06:06+00:00

If I import or create a pandas column that contains no spaces, I can

  • 0

If I import or create a pandas column that contains no spaces, I can access it as such:

from pandas import DataFrame

df1 = DataFrame({'key': ['b', 'b', 'a', 'c', 'a', 'a', 'b'],
                 'data1': range(7)})

df1.data1

which would return that series for me. If, however, that column has a space in its name, it isn’t accessible via that method:

from pandas import DataFrame

df2 = DataFrame({'key': ['a','b','d'],
                 'data 2': range(3)})

df2.data 2      # <--- not the droid I'm looking for.

I know I can access it using .xs():

df2.xs('data 2', axis=1)

There’s got to be another way. I’ve googled it like mad and can’t think of any other way to google it. I’ve read all 96 entries here on SO that contain "column" and "string" and "pandas" and could find no previous answer. Is this the only way, or is there something better?

  • 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-15T15:06:08+00:00Added an answer on June 15, 2026 at 3:06 pm

    I think the default way is to use the bracket method instead of the dot notation.

    import pandas as pd
    
    df1 = pd.DataFrame({
        'key': ['b', 'b', 'a', 'c', 'a', 'a', 'b'],
        'dat a1': range(7)
    })
    
    df1['dat a1']
    

    The other methods, like exposing it as an attribute are more for convenience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll probably must create import script from Joomla. How I can detect that selected
I have a pandas dataframe in which one column of text strings contains comma-separated
I need to create a new DB2 instance and import a database from the
is it possible to create a java application that will import excel files .
i need to create a object Image from import javax.microedition.lcdui.Image; using a file .png
Code replicating the error: from sqlalchemy import create_engine, Table, Column, Integer from sqlalchemy.ext.declarative import
When I create a DataFrame, then sort by a column it appears to be
I have this code to create a database: from sqlalchemy import create_engine from sqlalchemy
Here's my code: from sqlalchemy import create_engine, Column, Integer from sqlalchemy.ext.declarative import declarative_base from
I have a Python module that I import from my C++ code (I'm embedding

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.