Difference between list and tuple in python
πΈList is mutable ( you can modify the original list) and it's values are written in sqare brackets [ ]
πΈTuple is immutable ( you can't modify it) and it's values are written in parentheses ( ) delimited by comma( , )
πΈTo convert list to tuple - we use tuple() function
list1 = [1,2,3]
print(tuple(list1)) Output : (1,2,3)
πΈ For single element list
list1 = [1]
print(tuple(list1)) Output : (1, )
βͺοΈa tuple is a tuple because of comma not because of parentheses
@Python_Codes
πΈList is mutable ( you can modify the original list) and it's values are written in sqare brackets [ ]
πΈTuple is immutable ( you can't modify it) and it's values are written in parentheses ( ) delimited by comma( , )
πΈTo convert list to tuple - we use tuple() function
list1 = [1,2,3]
print(tuple(list1)) Output : (1,2,3)
πΈ For single element list
list1 = [1]
print(tuple(list1)) Output : (1, )
βͺοΈa tuple is a tuple because of comma not because of parentheses
@Python_Codes
To shuffle pandas DataFrame df
df = df.sample(frac=1, random_state=123).reset_index(drop=True)
Alternatively, you can use sklearn.utils.shuffle().
#pandas
@Python_Codes
(
in a reproducible way):df = df.sample(frac=1, random_state=123).reset_index(drop=True)
Alternatively, you can use sklearn.utils.shuffle().
#pandas
@Python_Codes
Do you know abou .strip()
From the above example you can see that it removed all the characters mentioned in .strip('comw.') and returns the remaining string
@Python_Codes
From the above example you can see that it removed all the characters mentioned in .strip('comw.') and returns the remaining string
@Python_Codes
Useful PandasπΌ method you should definitely know
β head()
β info()
β fillna()
β melt()
β pivot()
β query()
β merge()
β assign()
β groupby()
β describe()
β sample()
β replace()
β rename()
@Python_Codes
β head()
β info()
β fillna()
β melt()
β pivot()
β query()
β merge()
β assign()
β groupby()
β describe()
β sample()
β replace()
β rename()
@Python_Codes
π‘ Python Tip: Do you know Ellipsis(...) can be used as a placeholder in Python, just like a π±π’π΄π΄ statement?
@Python_Codes
@Python_Codes
π‘ Python Life Hack: Do you know you can copy the files from a computer to a mobile phone π± without any cable using Python π ?
@Python_Codes
@Python_Codes
Python Class Anatomy
Almost everything a Python class definition can contain summed up in one image :)
@Python_Codes
Almost everything a Python class definition can contain summed up in one image :)
@Python_Codes
Python Tip:
You can use dict o
@Python_Codes
You can use dict o
n a clas
s instance to get all instance attributes as a dictionary@Python_Codes
Python Tip:
You can use the calendar module in one line from the command line with python -m calendar
@Python_Codes
You can use the calendar module in one line from the command line with python -m calendar
@Python_Codes