5

I'm appending some weather data (from json- dict) - in Japanese to DataFrame.

I would like to have something like this

        天気             風
 0  状態: Clouds    風速: 2.1m
 1     NaN          向き: 230

But I have this

        天気             風
 0  状態: Clouds        NaN
 1      NaN          風速: 2.1m
 2      NaN           向き: 230

How Could I change the Codes to make it like that? Here is the code

df = pd.DataFrame(columns=['天気','風'])
df = df.append({'天気': weather_status}, ignore_index=True) # 状態: Clouds - value
df = df.append({'風': wind_speed}, ignore_index=True) # 風速: 2.1m -value
df = df.append({'風': wind_deg}, ignore_index=True) # 向き: 230 -value
print(df)

1 Answer 1

2

One way could be:

df = pd.DataFrame(columns=['天気','風'])
df = df.append({'天気': weather_status, '風': wind_speed}, ignore_index=True)
df = df.append({'風': wind_deg}, ignore_index=True)
print(df)

And print without index

print(df.to_string(index=False))
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to lose that index numbers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.