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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.