If you only need to get list of unique values, you can just use unique method. If you want to have Python's set, then do set(some_series)

In [1]: s = pd.Series([1, 2, 3, 1, 1, 4])

In [2]: s.unique()
Out[2]: array([1, 2, 3, 4])

In [3]: set(s)
Out[3]: {1, 2, 3, 4}

However, if you have DataFrame, just select series out of it ( some_data_frame['<col_name>'] ).

Answer from grechut on Stack Overflow
Discussions

Convert dataframe rows into sets
I'm curious what you want this for! I've assumed your dataframe comes with each of your variables in their own column so this starts with a bit to combine a row into a tuple. Then it aggregates the tuples belonging to each set. #Make your example dataframe data=[["set1","a",9,10], ["set1","b",14,100], ["set2","c",5,69], ["set2","d",4,100]] df=pd.DataFrame(columns=["Set","var1","var2","var3"],data=data) #turn your columns into tuples df["tuple"]=list(df[["var1","var2","var3"]].to_records()) #combine df=df.groupby("Set")["tuple"].agg(lambda x: [y for y in x]).reset_index() More on reddit.com
🌐 r/learnpython
13
4
June 30, 2021
python - How to set the columns in pandas - Stack Overflow
Here is my dataframe: Dec-18 Jan-19 Feb-19 Mar-19 Apr-19 May-19 Saturday 2540.0 2441.0 3832.0 4093.0 1455.0 2552.0 Sunday 1313.0 1891.0 2968.0 2260.0 1454.0 1798.0 More on stackoverflow.com
🌐 stackoverflow.com
July 2, 2019
Changing negative values to 0 in pandas
I’m new to pandas but wouldn’t a Boolean expression solve your problem? Something like Final[final[:]<0] =0 More on reddit.com
🌐 r/learnpython
4
1
July 23, 2019
Pandas quantizing column values to allowed set of values.
So, this looks like youre rounding, is that right? I can't say that I have the most extensive experience with pandas (still working on it), but the way that I might approach this is iterrows, applying a self-defined function (containing a set of nested if statements) via lambda maybe? That certainly would work, but I don't know if that's the elegant manner in which you're looking for. If you're asking about a native Pandas method, I personally don't know, but I think itterow, and lambda to apply to a new column. I'm sorry if this isn't really what you're looking for! More on reddit.com
🌐 r/learnpython
3
2
February 26, 2018
🌐
Finxter
blog.finxter.com › 5-best-ways-to-convert-pandas-dataframe-column-values-to-a-set
5 Best Ways to Convert Pandas DataFrame Column Values to a Set – Be on the Right Side of Change
February 19, 2024 - This method involves directly converting the column values into a list and then casting it to a set. The set() function is a Python built-in that creates a set from an iterable. This method is straightforward and the go-to for a quick conversion. ... import pandas as pd # Creating a pandas ...
🌐
Medium
medium.com › @whyamit101 › pandas-set-column-names-a-comprehensive-guide-130c84f8761a
Pandas Set Column Names: A Comprehensive Guide | by why amit | Medium
April 12, 2025 - When you work with data in Python, specifically using the pandas library, one of the first things you might want to do is set or change the column names of your DataFrame.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.html
pandas.DataFrame — pandas 3.0.3 documentation - PyData |
If data contains column labels, will perform column selection instead. ... Data type to force. Only a single dtype is allowed. If None, infer.
🌐
TutorialKart
tutorialkart.com › python › pandas › pandas-dataframe-set-column-names
How to set Column Names for DataFrame in Pandas?
July 9, 2021 - To set column names of DataFrame in Pandas, use pandas.DataFrame.columns attribute. Assign required column names as a list to this attribute.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
Alternatively, use a mapping, e.g. {col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. ... This keyword is now ignored; changing its value will have no impact on the method. Deprecated since version 3.0.0: This keyword is ignored and will be removed in pandas 4.0.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › convert dataframe rows into sets
r/learnpython on Reddit: Convert dataframe rows into sets
June 30, 2021 -

How can I convert my pandas dataframe into this format?

``` sets items weight value

0 set1 a 9 10

1 set1 b 14 100

2 set2 c 5 69

3 set2 d 4 100

Outcome i'm looking for:

set1 = (("a", 9, 10), ("b", 14, 100))

set2 = (("c", 5, 69), ("d", 4, 100))

print(set1)

set1 = (("a", 9, 10), ("b", 14, 100))

Top answer
1 of 2
3
I'm curious what you want this for! I've assumed your dataframe comes with each of your variables in their own column so this starts with a bit to combine a row into a tuple. Then it aggregates the tuples belonging to each set. #Make your example dataframe data=[["set1","a",9,10], ["set1","b",14,100], ["set2","c",5,69], ["set2","d",4,100]] df=pd.DataFrame(columns=["Set","var1","var2","var3"],data=data) #turn your columns into tuples df["tuple"]=list(df[["var1","var2","var3"]].to_records()) #combine df=df.groupby("Set")["tuple"].agg(lambda x: [y for y in x]).reset_index()
2 of 2
2
Note that in your example your set1 and set2 are actually tuples, not sets. I'll assume tuples/lists are what you want, and that you just mean "set" in the mathematical sense as a collection of related elements rather than an actual Python set. I don't think it's possible to use the values in a column as variable names, which is what it seems you want to do with your sets column. Someone will correct me if I'm wrong on that, I hope. However, the logic for creating nested groups based on the sets column is as follows: >>> [g.drop(columns=['sets']).values.tolist() for _, g in df.groupby('sets')] [[['a', 9, 10], ['b', 14, 100]], [['c', 5, 69], ['d', 4, 100]]] Alternatively, if you do want to be able to query your data by set name, different from but similar to print(set1), you can do it this way: >>> sets = df.set_index('sets').groupby('sets').apply(pd.Series.tolist) >>> sets sets set1 [[a, 9, 10], [b, 14, 100]] set2 [[c, 5, 69], [d, 4, 100]] >>> print(sets['set1']) [['a', 9, 10], ['b', 14, 100]]
🌐
IncludeHelp
includehelp.com › python › create-a-set-from-a-series-in-pandas.aspx
Python - Create a set from a series in pandas
To create a set from a series in pandas, you have to first find the unique elements using the series.unique() method and then convert it into a set by using the set() method which is an inbuilt method in Python.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.assign.html
pandas.DataFrame.assign — pandas 3.0.3 documentation
The column names are keywords. If the values are callable, they are computed on the DataFrame and assigned to the new columns. The callable must not change input DataFrame (though pandas doesn’t check it). If the values are not callable, (e.g.
🌐
Built In
builtin.com › data-science › pandas-add-column
How to Add Columns in a Pandas DataFrame | Built In
Summary: Five methods for adding columns to a Pandas DataFrame include direct assignment, insert(), .loc[], .assign() and Python dictionary mapping. Each approach includes concise examples for quick application in data workflows. more Five methods ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › create a set from a series in pandas
Create a Set From a Series in Pandas - Spark By {Examples}
March 27, 2024 - We can create a set from a series of pandas by using set(), Series.unique() function. The set object is used to store multiple items which are
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › create-a-set-from-a-series-in-pandas
Create A Set From A Series In Pandas - GeeksforGeeks
July 23, 2025 - We can directly apply set() function to the pandas series, the set function automatically convert the pandas series into a set. ... In conclusion, creating a set from a Pandas Series in Python is a useful technique for data manipulation.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-set-cell-value-in-pandas-dataframe
How to Set Cell Value in Pandas DataFrame? - GeeksforGeeks
July 23, 2025 - Here we are using the Pandas loc() method to set the column value based on row index and column name ... # create a dataframe # with 3 rows and 3 columns data = pd.DataFrame({ 'name': ['sireesha', 'ravi', 'rohith', 'pinkey', 'gnanesh'], 'subjects': ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Set a column as the DataFrame index with set_index() | note.nkmk.me
January 26, 2024 - The set_index() method of pandas.DataFrame allows you to set an existing column as the index (row labels). pandas.DataFrame.set_index — pandas 2.1.4 documentation How to use set_index()Basic usageKee ...
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.1 documentation
Alternatively, use a mapping, e.g. {col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. ... This keyword is now ignored; changing its value will have no impact on the method. Deprecated since version 3.0.0: This keyword is ignored and will be removed in pandas 4.0.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.at.html
pandas.DataFrame.at — pandas 3.0.2 documentation - PyData |
Access a single value for a row/column label pair. Similar to loc, in that both provide label-based lookups. Use at if you only need to get or set a single value in a DataFrame or Series.