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
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.set_index.html
pandas.DataFrame.set_index — pandas 3.0.3 documentation
Whether to append columns to existing index. Setting to True will add the new columns to existing index.
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 - Set value on an entire column of a pandas dataframe - Stack Overflow
I'm trying to set the entire column of a dataframe to a specific value. In [1]: df Out [1]: issueid industry 0 001 xxx 1 002 xxx 2 003 xxx 3 004 xxx 4 005 xxx · From what I've seen, loc is the best practice when replacing values in a dataframe (or isn't it?): ... A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead ... I got the same warning message. Any ideas? Working with Python 3.5.2 and pandas ... More on stackoverflow.com
🌐 stackoverflow.com
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
Convert dataframe rows into sets : r/learnpython
🌐 r/learnpython
🌐
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.
🌐
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.
🌐
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 ...
🌐
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]]
🌐
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
Find elsewhere
🌐
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.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
Use a str, numpy.dtype, pandas.ExtensionDtype or Python type to cast entire pandas object to the same type. 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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-set-cell-value-in-pandas-dataframe
How to Set Cell Value in Pandas DataFrame? - GeeksforGeeks
July 23, 2025 - This method is used to set the value of an existing value or set a new record. ... # import pandas module import pandas as pd # create a dataframe # with 3 rows and 3 columns data = pd.DataFrame({ 'name': ['sireesha', 'ravi', 'rohith', 'pinkey', 'gnanesh'], 'subjects': ['java', 'php', 'html/css', 'python', 'R'], 'marks': [98, 90, 78, 91, 87] }) # set value at 6 th location for name column data.at[5, 'name'] = 'sri devi' # set value at 6 th location for subjects column data.at[5, 'subjects'] = 'jsp' # set value at 6 th location for marks column data.at[5, 'marks'] = 100 # display data
🌐
IncludeHelp
includehelp.com › python › create-a-set-from-a-series-in-pandas.aspx
Python - Create a set from a series in pandas
Just like list, tuple, and dictionary, the set is another built-in data type in python which is used to store elements. Elements inside a set are unique that is there is only 1 occurrence of each element inside a set. Given a pandas series, we have to convert it into a set.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-set-dtypes-by-column-in-pandas-dataframe
How to Set dtypes by Column in Pandas DataFrame | Saturn Cloud Blog
November 13, 2023 - In the above code, we first create a sample DataFrame df with columns A, B, and C. We then use the astype() method to set the dtypes for each column. Note that we specify the dtype we want to cast to inside the astype() method.
🌐
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 - Yes, while pandas allows repeated column names, it’s best practice to keep them unique to avoid confusion during data manipulation and analysis. How can I check the current column names in a DataFrame? You can check the column names of a DataFrame easily using df.columns, which returns an index object containing the list of column names. Setting and changing column names is an essential skill in data manipulation with pandas.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.assign.html
pandas.DataFrame.assign — pandas 3.0.1 documentation
October 17, 2021 - 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.
🌐
Pandas
pandas.pydata.org › docs › getting_started › intro_tutorials › 05_add_columns.html
How to create new columns derived from existing columns — pandas 3.0.3 documentation
NaN [5 rows x 5 columns] The calculation is again element-wise, so the / is applied for the values in each row. Other mathematical operators (+, -, *, /, …) and logical operators (<, >, ==, …) also work element-wise. The latter was already used in the subset data tutorial to filter rows of a table using a conditional expression.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › article › python-typecasting-pandas-into-set
Python - Typecasting Pandas into set
March 26, 2026 - Use set(dataframe.column) to convert Pandas columns into sets for duplicate removal and set operations.
🌐
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.