--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCL%2BRD8BefHOSEYaemjmAjnMam_b7Xx38HmR%3DXzamvU%3DBjw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CA%2BXMcTP0G5QhoV_-3veXVCrWEQs79s_E5ASTMkp_EBZcGLLdog%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCLJkH2ZKSV_qiyw5Z3pEGUiO5dGJAQNu2y%3DBgYtrs4BVzQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CA%2BXMcTMXuzpn%2BPUbWyTn-5mR1ibmkRVTQEOFsG18VPoq%3Db3p7A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCLL2PnZo6AJNtuWq1SsJvpwa47NruJ6SXLNgG%3DnYttAwrA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCLL2PnZo6AJNtuWq1SsJvpwa47NruJ6SXLNgG%3DnYttAwrA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/2D2EA316-CA0D-4E2F-9F09-CADC940F0B42%40gmail.com.
Le 20 janv. 2023 à 18:58, Elvis Shera <elvis...@gmail.com> a écrit :
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCL%2BPDOxrMaWmaPMat%2BscJwOBYg5Dw6Ktohud5mF93ZoOEw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAB6X4shG-XZDUKJFmEEdJC%3DRtHY4Q9t%3DojDMjKTdwpBt1hwkGg%40mail.gmail.com.
Le 22 janv. 2023 à 16:11, Elvis Shera <elvis...@gmail.com> a écrit :
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCLJboQAv5VG4cUk6EuN6SGUqTaZ5UeQfLH7uva3jJd9HpQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/E4E134CE-CF98-4927-9512-A160CB7A378F%40gmail.com.
Hi,
I hope this example will help. Cut and paste in a .py file and run it.
# ==============================
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 2 15:41:10 2023
@author: Nicolas
"""
import pandas as pd
df = pd.DataFrame(
{
"Name": [
"Braund, Mr. Owen Harris",
"Allen, Mr. William Henry",
"Bonnell, Miss. Elizabeth",
],
"Age": [22, 55, 22],
"Sex": ["male", "male", "female"],
"Gen":['unknow', 'unknow', 'unknow']
}
)
print(df)
# update a value
df.loc[df['Age'] > 50,'Gen'] = 'x'
print(df,'\n')
# change a value
df.loc[df['Age'] > 50,'Age'] = 50
print (df,'\n')
# print unique values for 'Age'
print(df['Age'].unique)
print('\n')
# returns a boolean series where age is 22. This is a loop and
this is fast.
df_bool = df['Age'] == 22
print(df_bool,'\n')
# The wrong way to do a loop with pandas. This is slow
for x in df['Age']:
if x == 22:
print (True)
else:
print(False)
# Adding df[] in front will return the df where the condition
applies
df0 = df[df['Sex'] == 'male']
print(df0,'\n')
df1 = df[df['Age'] == 22 ]
print (df1,'\n')
# multiple conditions
df2 = df[(df['Age'] == 22) & (df['Sex'] == 'female')]
print(df2,'\n')
# ==============================
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAOeUCLJboQAv5VG4cUk6EuN6SGUqTaZ5UeQfLH7uva3jJd9HpQ%40mail.gmail.com.
-- Nicolas Cadieux https://gitlab.com/njacadieux