To see the variety of values in an individual column of your DataFrame, you can use the name of the DataFrame column (in this case ‘Y’) and place it into a set, then print the values in the set. For example: # Check the variety of values in the Y column prop_variety = set(my_dataframe[“Y”]) prop_variety … Continue reading Pandas: How to see the variety of values in a DataFrame column
Pandas
Pandas: How to export a DataFrame to .csv
Here is a function I wrote that will export an entire DataFrame to csv. It uses the Pandas function to_csv(). Just feed it the name of the DataFrame and the name you want for the .csv file. def dataframe_to_csv(filename, DataFrame): “””Export entire DataFrame to csv.””” output = DataFrame output.to_csv(filename, index=True) The filename can be a … Continue reading Pandas: How to export a DataFrame to .csv
Pandas: How to get a random sample DataFrame of x length using .sample( )
Let’s say you have a Pandas DataFrame called ‘df’ that has 50 thousand rows in it and you want to get a random sample out of it that contains 300 records. Pandas has a built in function called sample() that makes this very easy. All you have to do is decide on the name of … Continue reading Pandas: How to get a random sample DataFrame of x length using .sample( )