#๐ How do I print 2 columns from a given data set ?
21 messages ยท Page 1 of 1 (latest)
@stark warren
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.
k=df2[(df2['JoinDate']>='2023-01-01')&(df2['JoinDate']<='2023-12-31')][['FirstName', 'LastName']]
I guess?
for one thing, make sure that the JoinDate column is encoded as datetimes. not as strings that are formatted as timestamps.
You would then just do df2.loc[df2['JoinDate'].dt.year == 2023, [['FirstName', 'LastName']]
you never want to have pandas expressions that look like df[ ][ ], with stacked getitem calls.
Shows error
you have to encode the JoinDate column as a datetime type
!docs pandas.to_datetime
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.
Be sure to always encode columns that represent times as datetime types--never leave them as strings.
how do I encode ??
It seems to be a new term to me
go to this page and read the instructions and examples: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html#pandas.to_datetime
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 ??
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.