Thanks to antville.org
setting colors in pandas

This is how to set the colors in pandas

mapper = {v: k for k, v in enumerate(colors.unique())}

ccolors.cat.reorder_categories(mapper).cat.codes

... Link (0 comments) ... Comment


apply colors to pandas

Here is how to change the color of negative values to red in pandas.

def color_negative_red(val):
color = 'red' if val < 0 else 'black'
return 'color: %s' % color

df = df.style.applymap(color_negative_red)

... Link (0 comments) ... Comment


14 days ago

This is the python way of calculating the date that is 14 days ago.

import datetime
(datetime.datetime.now() - datetime.timedelta(days = 14)).date()

And this is pandas way of getting the same results:

import pandas as pd
(pd.datetime.today() - pd.offsets.Day(14)).floor('D')

... Link (0 comments) ... Comment


Change default head rows from 5 to 3

from functools import partialmethod
pd.DataFrame.head = partialmethod(pd.DataFrame.head, n=3)

... Link (0 comments) ... Comment


Infer types in pandas

This will return the mixed datatypes but this can be slow.

df.applymap(type).nunique() > 1

Better approach pythonic approach would be...

from pandas.api.types import infer_dtype

infer_dtype(df.A)
'mixed-integer'

df.apply(lambda x: 'mixed' in infer_dtype(x))

... Link (0 comments) ... Comment


Python objects and methods

Here are important python objects and their methods
int __mul__, __add__, __eq__, __ge__, __mod__, __pow__
float .is_integer()
string .upper(), .endswith(), .split()
bool .numerator .__abs__()
list .append, .pop, __len__() / slicing
tuple
dict .items(), .keys(), .values() / slicing
pd.Series .sum(), .stack(), .groupby(), .resample(), .sort_values(), .sort_index(), .iloc
pd.DataFrame

... Link (0 comments) ... Comment


JSON to DF

Here is how to read a JSON file into pandas dataframe.

import json
import pandas as pd

with open('/tmp/aclImdb/movie_data/gv.json', 'r') as f:
data = json.load(f)

df=pd.DataFrame(data['data'])
df.to_excel('gov.xlsx')

... Link (0 comments) ... Comment


Online for 8143 days
Last modified: 10/13/24, 10:18 AM
Status
Youre not logged in ... Login
Menu
... Home
... Tags

Search
Calendar
December 2024
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293031
October
Recent updates
Extract words Extract all incorrect
words in first.txt file and all correct ones in second.txt...
by shantanuo (10/13/24, 10:18 AM)
Remove hyperlink in LO writer
1) Select "Internet Link" from Character styles. 2) Right click...
by shantanuo (10/9/24, 8:09 AM)
Templates in LO writer 1)
File > Templates > Save as Template 2) Give it...
by shantanuo (10/9/24, 8:07 AM)
discretize continuous features You can
"discretize" or "bin" continuous features into categorical features. from sklearn.preprocessing...
by shantanuo (4/24/24, 9:33 AM)
User Defined Property You
can create User Defined Property in libreoffice writer. File – Properties...
by shantanuo (1/9/23, 8:52 AM)
Arranging Chapters in the Navigator
To use a custom paragraph style for a heading, choose...
by shantanuo (1/4/23, 8:26 AM)
Use focus mode using Android
phones Settings > Digital Wellbeing and parental controls. Tap your...
by shantanuo (1/1/23, 3:59 AM)
Embed Fonts in document If
you use a font that the recipient is unlike to...
by shantanuo (12/18/22, 10:07 AM)
Using Navigator in Writer To
open the Navigator, select View > Navigator, or press the...
by shantanuo (12/18/22, 10:06 AM)
More about hyphenation The settings
for Tools > Options > Language Settings > Writing Aids...
by shantanuo (12/18/22, 10:04 AM)
link or unlink template If
you are using Libre office then template changer extension is...
by shantanuo (12/16/22, 5:27 AM)
Finding Styles you can select
Edit > Find and Replace > Other Options > Paragraph...
by shantanuo (12/14/22, 7:17 AM)
regex in clac In LibreOffice
Calc, you can use function REGEX for e.g. Begins with...
by shantanuo (12/14/22, 4:40 AM)
Libre Calc tips Turn Off
Grid Lines If you want to turn off grid lines...
by shantanuo (12/13/22, 8:14 AM)
More about Styles You can
goto View - Styles and change "All Styles" to "Applied...
by shantanuo (12/13/22, 7:49 AM)
Page Break Before Every Chapter
If your chapter titles are using the "Heading 2" Style:...
by shantanuo (12/13/22, 6:36 AM)
View and print in different
color Displaying Color in LO but Printing as White Page...
by shantanuo (12/13/22, 6:26 AM)
Change Normal Template in Libreoffice
Writer 1) Open a new file and set your font;...
by shantanuo (12/12/22, 8:45 AM)
Short english words in Devanagari
The list of short english words written in Devanagari. #...
by shantanuo (10/5/22, 9:05 AM)
Card issuing banks CITI
Standard Chartered HSBC American Express HDFC ICICI AXIS INDUS IND Kotak...
by shantanuo (7/16/22, 4:46 AM)
Activate IAM Access To activate
the Activate IAM Access setting, you must log in to...
by shantanuo (7/12/22, 5:52 AM)
use cheat instead of man
wget https://github.com/cheat/cheat/releases/download/4.2.3/cheat-linux-arm64.gz gunzip cheat-linux-arm64.gz chmod 770 cheat-linux-arm64 ./cheat-linux-arm64 mv cheat-linux-arm64...
by shantanuo (7/4/22, 8:53 AM)
python module itertools list of
useful methods of itertools module. permutations combinations combinations_with_replacement zip_longest count...
by shantanuo (9/8/21, 7:50 AM)
wikipedia tools 1) Collection of
useful utilities https://wikipediatools.appspot.com/ 2) all history of a user https://xtools.wmflabs.org/ec/mr.wikisource.org/Shantanuo...
by shantanuo (8/20/21, 6:36 AM)
Duration/Term of Copyright In the
case of original literary, dramatic, musical and artistic works, the...
by shantanuo (8/20/21, 6:26 AM)

RSS feed

Made with Antville
Helma Object Publisher