Python Forum
Dataframe with array value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dataframe with array value
#1
Hello All,

I want to make a new dataframe for every unique value from a column.
For one specific column I can write it manually, but my script needs to be compatible with other columns as well.
So it should automatically detect the specific values of a column and than make new dataframes with the specific values.
I am still new to programming, but I cannot seem to find an answer to this problem, maybe someone on this forum knows how to do this
print(df['ent_name'].unique())

['DNS_8-WM2' 'DNS_8' 'DNS_8-WM1' 'DNS_8-WM5' 'DNS_8-LP1' 'DNS_8-LP2'
 'DNS_8-LP5' 'DNS_8-LP6' 'DNS_8-ATM1']

#making new dataframes manually
DNS_8 = df[df.ent_name == 'DNS_8']
DNS_8_WM1 = df[df.ent_name == 'DNS_8-WM1']
DNS_8_WM2 = df[df.ent_name == 'DNS_8-WM2']
DNS_8_WM5 = df[df.ent_name == 'DNS_8-WM5']

# Split data from Main tool and modules
Larz60+ write Mar-23-2021, 10:06 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use bbcode on future posts.
Reply
#2
Use an array to hold the dataframes

print(df['ent_name'].unique())
 
['DNS_8-WM2' 'DNS_8' 'DNS_8-WM1' 'DNS_8-WM5' 'DNS_8-LP1' 'DNS_8-LP2'
 'DNS_8-LP5' 'DNS_8-LP6' 'DNS_8-ATM1']
 
#making new dataframes
df_array = []
for name in df['ent_name'].unique() :
    df_array.append(df[df.ent_name == name]

# Split data from Main tool and modules
Reply
#3
Dear jef,

Thanks for your answer it helps a lot :)

Kind regards,

Tibo
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  converting dataframe to int numpy array glennford49 1 2,315 Apr-04-2020, 06:15 AM
Last Post: snippsat
  How to transform array into dataframe or table? python_newbie09 2 14,727 Mar-29-2019, 07:48 PM
Last Post: python_newbie09
  access a very large file? As an array or as a dataframe? Angelika 5 4,908 May-18-2017, 08:15 AM
Last Post: Angelika

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020