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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:34:01+00:00 2026-06-10T09:34:01+00:00

I have input data in a flattened file. I want to normalize this data,

  • 0

I have input data in a flattened file. I want to normalize this data, by splitting it into tables. Can I do that neatly with pandas – that is, by reading the flattened data into a DataFrame instance, and then applying some functions to obtain the resulting DataFrame instances?

Example:

Data is given to me on disk in the form of a CSV file like this:

ItemId   ClientId   PriceQuoted  ItemDescription
1        1          10           scroll of Sneak
1        2          12           scroll of Sneak
1        3          13           scroll of Sneak
2        2          2500         scroll of Invisible
2        4          2200         scroll of Invisible

I want to create two DataFrames:

ItemId   ItemDescription
1        scroll of Sneak
2        scroll of Invisibile

and

ItemId   ClientId   PriceQuoted
1        1          10
1        2          12
1        3          13
2        2          2500
2        4          2200

If pandas only has a good solution for the simplest case (normalization results in 2 tables with many-to-one relationship – just like in the above example), it might be enough for my current needs. I may need a more general solution in the future, however.

  • 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-10T09:34:02+00:00Added an answer on June 10, 2026 at 9:34 am
    In [30]: df = pandas.read_csv('foo1.csv', sep='[\s]{2,}')
    
    In [30]: df
    Out[30]:
       ItemId  ClientId  PriceQuoted      ItemDescription
    0       1         1           10      scroll of Sneak
    1       1         2           12      scroll of Sneak
    2       1         3           13      scroll of Sneak
    3       2         2         2500  scroll of Invisible
    4       2         4         2200  scroll of Invisible
    
    In [31]: df1 = df[['ItemId', 'ItemDescription']].drop_duplicates().set_index('ItemId')
    
    In [32]: df1
    Out[32]:
                ItemDescription
    ItemId
    1           scroll of Sneak
    2       scroll of Invisible
    
    In [33]: df2 = df[['ItemId', 'ClientId', 'PriceQuoted']]
    
    In [34]: df2
    Out[34]:
       ItemId  ClientId  PriceQuoted
    0       1         1           10
    1       1         2           12
    2       1         3           13
    3       2         2         2500
    4       2         4         2200
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input edit field where the user can enter data. I want
I have input data that contain lines like this: -0.438185 -0.766791 0.695282 0.759100 0.034400
I have some dirty input data that is being imported into a raw source
I have a large amount of input data that I want to compress to
I have a data input that looks like this: seq 75 T G -
I have bumped into this problem several times on the type of input data
I have a Flex Mobile Application that requires users to input data into a
I have this code that populates the div with the form input data: var
In my scenario, I have a program that analyzes data input files and produces
I have a streaming input which has repeated values. I can use any data

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.