Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
LegendaryTokash
Frequent Visitor

Python formatting for streaming dataset -formatting question

Alright, so I am not a developer by trade, but a windows infrastructure admin.  I dabble in electronics and automation, and have been doing odd experiments with Rpi and Arduino components for a couple of years now.   Only recently have I explored taking the realtime data I can collect and bundling it together for a practical purpose - and am exploring PowerBI as a method to visualize.

 

Long story short, I have a Rpi pulling data from an Arduino, temp, humidity, voltage and current information.  I'm following this guide on how to get started, and I am failing to understand the python formatting being done.  

https://powerbi.microsoft.com/en-us/blog/using-power-bi-real-time-dashboards-to-display-iot-sensor-d...  -- the only difference is i am not rewiring existing projects to read directly from the Pi, but using existing Python via Serial, to get my values.

Without taking a large number of hours to formally learn python, I have a moderate understanding of its syntax and controls, but I am struggling to understand and adapt this line:

 

# data that we're sending to Power BI REST API
data = '[{{ "timestamp": "{0}", "temperature": "{1:0.1f}", "humidity": "{2:0.1f}" }}]'.format(now, temp, humidity)

 

I need to understand how to replace the formatting components with a string and a float variable similar to below.  Ideally I'd like to better understand the formatting function, while I don't necessarily need it here, I am sure it will be useful in the future.  I've already populated the variables, and in my current iteration, pump that data into a mySQL database.   I am trying to eliminate that component overall, by leveraging streaming dataset instead.  Maybe it would be easier for me to understand this line with similar formatting, before i try and adjust the one used with the REST API.

 

print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temp, humidity)

 

 

 

Can someone give me a mid-level breakdown of what the formatting components of this line are?

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee


 

print 'Temp={0:0.1f} Humidity={1:0.1f}'.format(temp, humidity)

 


@LegendaryTokash

That formating is actually Python syntax specific. You would get more prompt response when asking in a Python community.

in the { }, the 0,1 before ":" are the the placeholder, which would be replaced with the arguments in format(temp, humidity). Regarding the 0.1f after ":", f stands for float type, 1f stands for the precision after decimial point, those 0.1f would be used to format the passed temp and humidity. For example, say temp=10, humidity=10.11, the print output would be like 

Temp=10.0, Humidity=10.1

 

For more details, you can check 

How does this formatting code work?

Python format samples

 

The stream dataset doesn't care from what language the data sent API is called, as long as the data json in the required format. If you have any question on Power BI, feel free to post. For any further question on Python, I'd suggest you post it in the Python community, as there're more Python experts.

View solution in original post

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee


 

print 'Temp={0:0.1f} Humidity={1:0.1f}'.format(temp, humidity)

 


@LegendaryTokash

That formating is actually Python syntax specific. You would get more prompt response when asking in a Python community.

in the { }, the 0,1 before ":" are the the placeholder, which would be replaced with the arguments in format(temp, humidity). Regarding the 0.1f after ":", f stands for float type, 1f stands for the precision after decimial point, those 0.1f would be used to format the passed temp and humidity. For example, say temp=10, humidity=10.11, the print output would be like 

Temp=10.0, Humidity=10.1

 

For more details, you can check 

How does this formatting code work?

Python format samples

 

The stream dataset doesn't care from what language the data sent API is called, as long as the data json in the required format. If you have any question on Power BI, feel free to post. For any further question on Python, I'd suggest you post it in the Python community, as there're more Python experts.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.