Last active
February 12, 2021 14:51
-
-
Save data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e to your computer and use it in GitHub Desktop.
Revisions
-
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,17 @@ # Pandas .describe() formatted Format numbers output from the pandas df.describe() method. For instance, instead of outputting scientific notation, we can have numbers with thousands separators and a desired number of decimals. When using .describe with an entire dataframe, use .apply and a lambda function to apply the formatting to every number. - To change the number of decimals, change the number before the f - To remove the thousands separator remove the comma `df.describe().apply(lambda s: s.apply('{:,.0f}'.format))` When using .describe with a single column or a series, use the .map method instead: `df['Column'].describe().map('{:,.0f}'.format)` For reference, see: - https://stackoverflow.com/a/47207283 - https://mkaz.blog/code/python-string-format-cookbook/ - https://docs.python.org/3/library/string.html#formatstrings -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ For reference, see: - https://mkaz.blog/code/python-string-format-cookbook/ When using describe with an entire dataframe, use .apply and a lambda function to apply the formatting to every number. - To change the number of decimals, change the number before the f - To remove the thousands separator remove the comma -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 12 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,17 @@ # Pandas Describe() formatted Format numbers output from the pandas df.describe() method. For instance, instead of outputting scientific notation, we can have numbers with thousands separators and a desired number of decimals. For reference, see: - https://stackoverflow.com/a/47207283 - https://mkaz.blog/code/python-string-format-cookbook/ When using describe for a data frame, use .apply and a lambda function to apply the formatting to every number. - To change the number of decimals, change the number before the f - To remove the thousands separator remove the comma `df.describe().apply(lambda s: s.apply('{:,.0f}'.format))` When using describe with a single column or a series, use the .map method instead: `df['Column'].describe().map('{:,.0f}'.format)` -
David Cochran renamed this gist
Feb 12, 2021 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ # Pandas Describe() formatted Format numbers output from the pandas df.describe() method. For instance, instead of outputting scientific notation, we can have numbers with thousands separators and a desired number of decimals. When using describe for a data frame, # Uses a lambda function to apply the formatting to every number # See https://stackoverflow.com/a/47207283 # See also https://mkaz.blog/code/python-string-format-cookbook/ -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,7 @@ # To change the number of decimals, change the number before the f # To remove the thousands separator remove the comma df.describe().apply(lambda s: s.apply('{:,.0f}'.format)) # Use .map for a series df['Column'].describe().map('{:,.0f}'.format) -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,9 @@ # Describe() formatted # Format numbers without scientific notation and with thousands separators # Uses a lambda function to apply the formatting to every number # See https://stackoverflow.com/a/47207283 # See also https://mkaz.blog/code/python-string-format-cookbook/ # To change the number of decimals, change the number before the f # To remove the thousands separator remove the comma df.describe().apply(lambda s: s.apply('{:,.0f}'.format)) -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ # Describe() formatted # Format numbers without scientific notation and with thousands separators # To change the number of decimals, change the number before the f # To remove the thousands separator remove the comma # See https://stackoverflow.com/a/47207283 # See also https://mkaz.blog/code/python-string-format-cookbook/ -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ # Describe() formatted # Format numbers without scientific notation and with thousands separators # To change the number of decimals, change the number before the f # See https://stackoverflow.com/a/47207283 # See also https://mkaz.blog/code/python-string-format-cookbook/ df.describe().apply(lambda s: s.apply('{:,.0f}'.format)) -
David Cochran revised this gist
Feb 12, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ # df.describe() with numbers converted to normal format with thousands separators # https://stackoverflow.com/a/47207283 # https://mkaz.blog/code/python-string-format-cookbook/ # To change the number of decimals, change the 0 to the desired number df.describe().apply(lambda s: s.apply('{:,.0f}'.format)) -
David Cochran created this gist
Feb 12, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # df.describe() with numbers converted to normal format with thousands separators # https://stackoverflow.com/a/47207283 # https://mkaz.blog/code/python-string-format-cookbook/ df.describe().apply(lambda s: s.apply('{:,.0f}'.format))