seaborn

Pandas format column as currency

泪湿孤枕 提交于 2020-03-20 01:20:12
问题 Given the following data frame: import pandas as pd df = pd.DataFrame( {'A':['A','B','C','D'], 'C':[12355.00,12555.67,640.00,7000] }) df A C 0 A 12355.00 1 B 12555.67 2 C 640.00 3 D 7000.00 I'd like to convert the values to dollars in thousands of USD like this: A C 0 A $12.3K 1 B $12.5K 2 C $0.6K 3 D $7.0K The second thing I need to do is somehow get these into a Seaborn heat map, which only accepts floats and integers. See here for more on the heat map aspect. I'm assuming once the floats

Seaborn - change bar color according to x name instead of hue?

若如初见. 提交于 2020-03-19 17:00:33
问题 For example: import seaborn as sns import pandas as pd import matplotlib.pyplot as plt sns.set_style('darkgrid') fig, ax = plt.subplots() a = pd.DataFrame({'Program': ['A', 'A', 'B', 'B', 'Total', 'Total'], 'Scenario': ['X', 'Y', 'X', 'Y', 'X', 'Y'], 'Duration': [4, 3, 5, 4, 9, 7]}) g = sns.barplot(data=a, x='Scenario', y='Duration', hue='Program', ci=None) I want x=X and x=Y have different color, but same color for each hue(A, B, Total ...) . ( There may be more Scenario than two ) . How do

Seaborn: Setting a distplot bin range?

[亡魂溺海] 提交于 2020-03-17 12:10:38
问题 So I have this data set showing the GDP of countries in billions (so 1 trillion gdp = 1000). import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('2014_World_GDP') df.sort('GDP (BILLIONS)',ascending=False, inplace=True) sorted = df['GDP (BILLIONS)'] fig, ax = plt.subplots(figsize=(12, 8)) sns.distplot(sorted,bins=8,kde=False,ax=ax) The above code give me the following figure: What I want to do whoever is set the bins

Seaborn: Setting a distplot bin range?

佐手、 提交于 2020-03-17 12:10:34
问题 So I have this data set showing the GDP of countries in billions (so 1 trillion gdp = 1000). import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('2014_World_GDP') df.sort('GDP (BILLIONS)',ascending=False, inplace=True) sorted = df['GDP (BILLIONS)'] fig, ax = plt.subplots(figsize=(12, 8)) sns.distplot(sorted,bins=8,kde=False,ax=ax) The above code give me the following figure: What I want to do whoever is set the bins

How to create a stacked bar chart for my DataFrame using seaborn? [duplicate]

大城市里の小女人 提交于 2020-03-17 03:49:45
问题 This question already has answers here : How to have clusters of stacked bars with python (Pandas) (7 answers) Closed 2 years ago . I have a DataFrame df : df = pd.DataFrame(columns=["App","Feature1", "Feature2","Feature3", "Feature4","Feature5", "Feature6","Feature7","Feature8"], data=[["SHA",0,0,1,1,1,0,1,0], ["LHA",1,0,1,1,0,1,1,0], ["DRA",0,0,0,0,0,0,1,0], ["FRA",1,0,1,1,1,0,1,1], ["BRU",0,0,1,0,1,0,0,0], ["PAR",0,1,1,1,1,0,1,0], ["AER",0,0,1,1,0,1,1,0], ["SHE",0,0,0,1,0,0,1,0]]) I want

How to create a stacked bar chart for my DataFrame using seaborn? [duplicate]

非 Y 不嫁゛ 提交于 2020-03-17 03:49:04
问题 This question already has answers here : How to have clusters of stacked bars with python (Pandas) (7 answers) Closed 2 years ago . I have a DataFrame df : df = pd.DataFrame(columns=["App","Feature1", "Feature2","Feature3", "Feature4","Feature5", "Feature6","Feature7","Feature8"], data=[["SHA",0,0,1,1,1,0,1,0], ["LHA",1,0,1,1,0,1,1,0], ["DRA",0,0,0,0,0,0,1,0], ["FRA",1,0,1,1,1,0,1,1], ["BRU",0,0,1,0,1,0,0,0], ["PAR",0,1,1,1,1,0,1,0], ["AER",0,0,1,1,0,1,1,0], ["SHE",0,0,0,1,0,0,1,0]]) I want

Stacked barchart in PairGrid python seaborn

允我心安 提交于 2020-03-16 07:52:07
问题 I whish to reproduce the PairGrid plot found in that tutorial, but locally my barcharts are not stacked as in the tutorial and I can't figure out how to make them so. import seaborn as sns import matplotlib.pyplot as plt # for graphics import os os.sys.version # '3.6.4 (default, Sep 20 2018, 19:07:50) \n[GCC 5.4.0 20160609]' sns.__version__ # '0.9.0' mpg = sns.load_dataset('mpg') g = sns.PairGrid(data=mpg[["mpg", "horsepower", "weight", "origin"]], hue="origin") g.map_upper(sns.regplot) g.map

How to plot a time-series to study frequency of items?

雨燕双飞 提交于 2020-03-05 06:06:32
问题 I would need to plot through time same values to see how frequency changes. In particular posts generated from different users through time. I have a dataset like the following: GENDER POST DATE COUNTER 0 men (post 103) 36 43 1 men (post 109) 38 2 2 men (post 116) 41 12 3 men (post 119) 42 32 4 men (post 124) 44 2 .. ... ... ... ... 82 women (post 83) 29 34 83 women (post 86) 30 2 84 women (post 86) 65 9 85 women (post 91) 32 5 86 women (post 99) 35 5 where DATE is numerical (sequential

How to plot a time-series to study frequency of items?

泪湿孤枕 提交于 2020-03-05 06:06:07
问题 I would need to plot through time same values to see how frequency changes. In particular posts generated from different users through time. I have a dataset like the following: GENDER POST DATE COUNTER 0 men (post 103) 36 43 1 men (post 109) 38 2 2 men (post 116) 41 12 3 men (post 119) 42 32 4 men (post 124) 44 2 .. ... ... ... ... 82 women (post 83) 29 34 83 women (post 86) 30 2 84 women (post 86) 65 9 85 women (post 91) 32 5 86 women (post 99) 35 5 where DATE is numerical (sequential

Side by Side BarPlot

故事扮演 提交于 2020-03-05 04:41:49
问题 I'm trying to create this kind of "side by side" barplot with seaborn and pandas . this is how I create data frame: dfs = pd.DataFrame(data={'investors': ['first','second','third'], 'stocks': [23, 123, 54], 'bonds': [54, 67, 123], 'real estate': [45, 243, 23]}) And here is barplot code: sns.factorplot(x='investors', y='bonds', data=dfs, kind='bar') Can anyone please help? Thanks 回答1: Use melt on your dateframe then plot it with seaborn. dfs = pd.DataFrame(data={'investors': ['first','second',