How do you format totalled 'y' axis numbers in the tooltip dialog box on a stacked column chart? - formatting

In order to format the tooltip y axis numbers, I specified the following formatting parameters in the 'tooltip:' tag...
tooltip: {
valueDecimals: 2, valuePrefix: '$',
I introduced another value, point.stackTotal(that sums the values in each stacked column to give me a total value). This number is NOT formatted!
How do I format this total number, for example, 6589.34, should be $6,589.34
Thank you in anticipation.
I tried specifying some formatting parameters in the 'tooltip:' tag...
tooltip: {
valueDecimals: 2, valuePrefix: '$',
This only works for the y axis values, for example, 2,345.3 becomes $2,345.30

Related

How to chart two metrics from aggregated table in Looker?

I am trying to make a line chart with two metrics vs date. I am querying an already aggregated table. When I add three columns to the visualization, date and 2 numeric fields and pick scatter plot or line chart, only two numeric fields are charted. I want to be able to chart date as X axis and two numeric fields as line chart.
Is there a way to chart two numeric dimensions in one chart without aggregation?
You need to have one dimension, which is the date, and two measures with type:number (because you don't need any aggregation)
measure: total_amount {
type: number
sql: ${pre_aggregated_total_amount} ;;
measure: product_count {
type: number
sql: ${pre_aggregated_product_count} ;;
Also, in the line chart option, you will be able to drag one measure to the left axis and the other one to the right axis if you want.

Use Row of Data Frame as X-Axis in Plotly Line Chart

I am trying to make a plotly line chart that shows team member progression with the following excel data:
For the life of me I cannot figure out how to set the team member names as the color for the lines, the x-axis as the months, and the y-axis as the numeric values. Closest I've gotten is a blank graph, and I've tried about 400 combinations of parameters for
px.line(
df,
color="Team_Member",
x = "the row of months... something with iloc maybe?",
y = df.columns,
title="Average Estimated Daily Working Hours by Team Member"
)

Replace selected values of one column with median value of another column but with condition

So, I hope you know the famous Titanic question. This is what I did so far by learning the tutorial. Now I want to replace NaN values of column: Age with median values of part of Age column. But the selected part should have a certain value for "Title"
For example, I want to replace NaN of Age where Title="Mr", so the median value for "Mr" would be filled in missing places which also has Title=="Mr".
I tried this:
for val in data["Title"].unique():
median_age = data.loc[data.Title == val, "Age"].median()
data.loc[data.Title == val, "Age"].fillna(median_age, inplace=True)
But still Age shows up as NaN. How can I do this?
Use combine_first to fill NaN. I have no column Title from my dataset but it's the same:
df['Age'] = df['Age'].combine_first(df.groupby('Sex')['Age'].transform('median'))

How to get the value of a cell based on filtering efficently

If I have a dataframe and want to have the value of a cell based on a condition/filter, it seems not to be a one line instruction.
In the example below I do not know the index at the beginning so I need to filter and then ask for index and apply it.
Is there a easier way to get the value without knowing the index upfront.
Edit: Easy spoken I want to have the value of the Column "Category" of the Row where the Column "No." has the value 'P1'.
You can use DataFrame.loc with specify condition and column name:
out = dfn.loc[dfn['No.'] == 'P1', 'Category']
Then out is Series, with one or more values, if no match get empty Series.
If need first value of out to scalar:
scalar = out.iat[0]
But this fail if empty Series:
out = dfn.loc[dfn['No.'] == 'aaaa', 'Category']
Then use:
scalar = next(iter(out), 'no match')

Pandas Data Frame Select column last value and replace with blank

I have a data frame with lots of columns, I wanted to replace the last value of few of columns with blank, what is the best way to do that.
the thing is data frame can be dynamic with values and length.
Here is the data frame:
enter image description here
How can I remove values from column F and G to blank?
please except typos as I'm new here.
df.loc[df.index[-1], ['G', 'F']] = np.nan