#๐Ÿ”’ How do I print 2 columns from a given data set ?

21 messages ยท Page 1 of 1 (latest)

stark warren
#

How do I print the first and last name alone for the year 2023 ??

k=df2[(df2['JoinDate']>='2023-01-01')&(df2['JoinDate']<='2023-12-31')]
print(k)```
This prints all the colums for joindate for the year 2023 . How do I just  print the last name and first name for the the year 2023 ??
I have attached the data set too
slender valveBOT
#

@stark warren

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

urban trout
#

k=df2[(df2['JoinDate']>='2023-01-01')&(df2['JoinDate']<='2023-12-31')][['FirstName', 'LastName']]
I guess?

tepid jewel
tepid jewel
tepid jewel
#

!docs pandas.to_datetime

slender valveBOT
#
pandas.to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, utc=False, format=None, exact=_NoDefault.no_default, unit=None, ...)```
Convert argument to datetime.

This function converts a scalar, array\-like, [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) or [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame)/dict\-like to a pandas datetime object.
tepid jewel
#

Be sure to always encode columns that represent times as datetime types--never leave them as strings.

stark warren
#

It seems to be a new term to me

tepid jewel
stark warren
#

okay

#
stud=pd.DataFrame({'Name':['Bell','lopez','hui'],'Age':[22,33,12],'Gender':['F','F','M'],'Mark':[100,89,99],'Score':[99,89,90]})
print(stud)
f=stud[stud['Gender']=='F']
print(f)

#count number of female students
c=f.count()
print(c)
#

I'm getting this as the output for the number of female students

#

How do I just get an output 3 ??

slender valveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.