Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

पायथन पैंडास - DateTimeIndex के साथ डेटाटाइम बनाएं

डेटाटाइम बनाने के लिए, हम date_range() का उपयोग करेंगे। पीरियड और टाइम ज़ोन को भी फ्रीक्वेंसी के साथ सेट किया जाएगा।

आवश्यक लाइब्रेरी आयात करें

import pandas as pd

DatetimeIndex बनाएं

पीरियड 8 और फ्रीक्वेंसी M (महीने) के साथ DatetimeIndex। टाइमज़ोन Australia/Sydney है:

datetime = pd.date_range('2021-09-24 02:35:55', periods=8, tz='Australia/Sydney', freq='M')

डेटाटाइम प्रदर्शित करें

print("DateTime...\n", datetime)

पूर्ण उदाहरण

import pandas as pd
datetime = pd.date_range('2021-09-24 02:35:55', periods=8, tz='Australia/Sydney', freq='M')
print("DateTime...\n", datetime)
print("\nGetting the day name..\n", datetime.day_name())
print("\nGetting the month name..\n", datetime.month_name())
print("\nGetting the year name..\n", datetime.year)
print("\nGetting the hour..\n", datetime.hour)
print("\nGetting the minutes..\n", datetime.minute)
print("\nGetting the seconds..\n", datetime.second)

आउटपुट

DateTime... DatetimeIndex(['2021-09-30 02:35:55+10:00', '2021-10-31 02:35:55+11:00', '2021-11-30 02:35:55+11:00', '2021-12-31 02:35:55+11:00', '2022-01-31 02:35:55+11:00', '2022-02-28 02:35:55+11:00', '2022-03-31 02:35:55+11:00', '2022-04-30 02:35:55+10:00'], dtype='datetime64[ns, Australia/Sydney]', freq='M')
Getting the day name.. Index(['Thursday', 'Sunday', 'Tuesday', 'Friday', 'Monday', 'Monday', 'Thursday', 'Saturday'], dtype='object')
Getting the month name.. Index(['September', 'October', 'November', 'December', 'January', 'February', 'March', 'April'], dtype='object')
Getting the year name.. Int64Index([2021, 2021, 2021, 2021, 2022, 2022, 2022, 2022], dtype='int64')
Getting the hour.. Int64Index([2, 2, 2, 2, 2, 2, 2, 2], dtype='int64')
Getting the minutes.. Int64Index([35, 35, 35, 35, 35, 35, 35, 35], dtype='int64')
Getting the seconds.. Int64Index([55, 55, 55, 55, 55, 55, 55, 55], dtype='int64')
  1. सीबॉर्न के साथ वायलिन प्लॉट बनाएं - पायथन पैंडास सीबॉर्न के साथ वायलिन प्लॉट बनाएं - पायथन पैंडास

    सीबॉर्न में वायलिन प्लॉट का उपयोग बॉक्सप्लॉट और कर्नेल डेंसिटी अनुमान के संयोजन को बनाने के लिए किया जाता है। इसके लिए seaborn.violinplot() का उपयोग किया जाता है।मान लीजिए हमारा डेटासेट CSV फ़ाइल के रूप में Cricketers.csv है।सबसे पहले, आवश्यक 3 लाइब्रेरी आयात करें:import seaborn as sb import pandas

  1. सीबॉर्न के साथ बॉक्स प्लॉट बनाएं - पायथन पैंडास सीबॉर्न के साथ बॉक्स प्लॉट बनाएं - पायथन पैंडास

    सीबॉर्न में बॉक्स प्लॉट का उपयोग श्रेणियों के संबंध में वितरण दिखाने के लिए बॉक्स प्लॉट बनाने के लिए किया जाता है। इसके लिए seaborn.boxplot() का उपयोग किया जाता है।मान लीजिए हमारा डेटासेट CSV फ़ाइल के रूप में Cricketers.csv है।सबसे पहले, आवश्यक 3 लाइब्रेरी आयात करें:import seaborn as sb import panda

  1. सीबॉर्न के साथ स्कैटर प्लॉट बनाएं - पायथन पैंडास सीबॉर्न के साथ स्कैटर प्लॉट बनाएं - पायथन पैंडास

    सीबॉर्न में स्कैटरप्लॉट का उपयोग कई सिमेंटिक ग्रुपिंग की संभावना के साथ स्कैटर प्लॉट बनाने के लिए किया जाता है। इसके लिए seaborn.scatterplot() का उपयोग किया जाता है।मान लीजिए हमारा डेटासेट CSV फ़ाइल के रूप में Cricketers.csv है।सबसे पहले, आवश्यक 3 लाइब्रेरी आयात करें:import seaborn as sb import pand