Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
Let's say that you have an insanely large dataframe with several observations (rows) and labels/characteristics (columns) and the first thing you want to do is to exclude all the columns who has irrelevant informantion. For that, you need to first of all, glance over the different values the columns, but you can't truly do that with head or tail.
Is there a fuction who returns all the non-repeated values of the columns of a dataframe instead of doing column by column? Thank in advance
I'm able to do it with single columns through the fuction unique. For example using df.color.unique(), it gives me the list of the different colors that there are but I want to do it directly for all of the 100 colums of my dataframe
You can use a for loop, in order to know all the unique value for each columns
for column in df.columns:
print(f"{column}: {df[column].unique()}")
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I'm new to python, and I'm a bit confused about the use cases of data types in python
Can someone please explain in detail when to use each data type, with an example if possible
Thank you.
Lists are used when you have data you want to further modify, alter like sorting and all.
Dictionary is used when you have to sets of data where data of the first set corresponds to data of other set. And the position of the data doesn't matter only the relation of the two sets matters.
A tuple is used when position of the data is very important and you don't want to alter the position throughout.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have list, its elements are also a list.
eg:
outlier=[[20,2,67], [90,6,12], [23,16,7]].
how I write a single line code to loop outlier list by taking elements from same index.I want to store the looping result as a list.
The question is not very clear to me, but if you want to make a new list that contains the first element of each list you have, then this is an example to take first element(x[0]) from each list and store them in a new list called "new_list":
new_list = [x[0] for x in outlier]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a csv file that contains the attendance of a few students on particular dates.
Here is my csv file
Name,RollNumber,Attendance,Date,Day,Time
student1,1,Present,1/30/2019,Wednesday,12:34:05
student2,2,Present,1/30/2019,Wednesday,12:34:05
student3,3,Present,1/30/2019,Wednesday,12:34:05
student4,4,Present,1/30/2019,Wednesday,12:34:05
student1,1,Absent,1/31/2019,Thursday,23:34:05
student2,2,Present,1/31/2019,Thursday,23:34:05
student3,3,Present,1/31/2019,Thursday,23:34:05
student4,4,Present,1/31/2019,Thursday,12:34:05
student1,1,Present,2/1/2019,Friday,12:34:05
student2,2,Absent,2/1/2019,Friday,12:34:05
student3,3,Absent,2/1/2019,Friday,12:34:05
student4,4,Present,2/1/2019,Friday,12:34:05
student1,1,Absent,2/2/2019,Saturday,12:34:05
student2,2,Absent,2/2/2019,Saturday,12:34:05
student3,3,Absent,2/2/2019,Saturday,12:34:05
student4,4,Absent,2/2/2019,Saturday,12:34:05
I want to plot a graph that show the number of students present and absent on each date from the csv file. How do I do this with matplotlib?
The easiest way in my opinion is to work with pandas pivot_table as follow:
df = pd.read_csv('your_csv_filepath_here')
# Create a duplicate of your target value
df['attendance'] = a.Attendance
# Pivot your dataframe
df_pivot = df.pivot_table(index=['Date'], columns='Attendance', values='attendance', aggfunc='count')
# Plot it using pandas (barplot is probably what you want)
df_pivot.plot(kind='bar')
Of course further plot customizations are possible, as well as other methods would achieve the same result
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Read each line in a text file, store the values in a list, and compute scores
The best approach this problem is to list all the functions you need to do the task. A typical example is:
Read file.
Read list.
Take list and get each string delimited by space.
Store string into an array.
...
Then go to the Python website and lookup how to do each function.
Example: To do input and output function in python:
https://docs.python.org/2/tutorial/inputoutput.html
Also, you can look up function by asking google. Google will then point you to answers to your questions:
Q: How to find mean of a list?
A: Finding the average of a list
If you do this enough times, eventually you will be able to write a problem that solves the problem listed.
Good Luck!